Last active
December 17, 2015 16:59
-
-
Save pjsvis/5642410 to your computer and use it in GitHub Desktop.
jquery.flot.stackedline directive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('flot') | |
.directive('flotStackedline', [function () { | |
'use strict'; | |
return { | |
restrict: 'EA', | |
require: 'ngModel', | |
link: function (scope, elem, attrs, ngModel) { | |
var chart = null, | |
opts = { | |
width:attrs.width || '100%', | |
height : attrs.height || attrs.width * 3 / 4, | |
label: attrs.label, | |
series: { | |
stack:true, | |
lines:{ | |
show:true, | |
fill:true | |
} | |
}, | |
xaxis: { mode: "time" }, | |
legend:{position: "nw"} | |
}; | |
var render=function(){ | |
var data = ngModel.$viewValue; | |
if(angular.isUndefined(data)){ | |
return; | |
} | |
chart = $.plot(elem, data, opts); | |
elem.show(); | |
}; | |
scope.$watch(attrs.ngModel, function () { | |
render(); | |
}); | |
$(window).resize(function(){ | |
render(); | |
}); | |
} | |
}; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment