Skip to content

Instantly share code, notes, and snippets.

@runxc1
Forked from jrmoran/app.js
Last active November 24, 2015 05:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save runxc1/7ab54ddc156dd8e33ac0 to your computer and use it in GitHub Desktop.
Save runxc1/7ab54ddc156dd8e33ac0 to your computer and use it in GitHub Desktop.
var App = angular.module('App', []);
App.controller('Ctrl', function($scope){
$scope.data1 = [ [[0, 1], [1, 5], [2, 2]] ];
$scope.data2 = [ [[0, 4], [1, 2], [2, 4]] ];
});
App.directive('chart', function(){
return{
restrict: 'A',
link: function(scope, elem, attrs){
var chart = null,
opts = { };
var data = scope[attrs.ngModel];
scope.$watch(attrs.chart, function(v){
if(!chart){
chart = $.plot(elem, v , opts);
elem.show();
}else{
chart.setData(v);
chart.setupGrid();
chart.draw();
}
});
}
};
});
<div ng-app='App'>
<div ng-controller='Ctrl'>
<div chart='data1'> </div>
<div chart='data2'> </div>
</div>
chart{
display:none;
width:400px;
height:200px;
}​
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment