Example: http://jsfiddle.net/jaimem/TDwGF/
-
-
Save meteorfox/9939389 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var App = angular.module('App', []); |
This file contains hidden or 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
App.controller('Ctrl', function($scope){ | |
var data1 = [ [[0, 1], [1, 5], [2, 2]] ], | |
data2 = [ [[0, 4], [1, 2], [2, 4]] ], | |
curr = 1; | |
$scope.data = data1; | |
$scope.change = function(){ | |
if(curr === 1){ | |
$scope.data = data2; | |
curr = 2; | |
}else{ | |
$scope.data = data1; | |
curr = 1; | |
} | |
}; | |
}); |
This file contains hidden or 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
App.directive('chart', function(){ | |
return{ | |
restrict: 'E', | |
link: function(scope, elem, attrs){ | |
var chart = null, | |
opts = { }; | |
var data = scope[attrs.ngModel]; | |
scope.$watch('data', function(v){ | |
if(!chart){ | |
chart = $.plot(elem, v , opts); | |
elem.show(); | |
}else{ | |
chart.setData(v); | |
chart.setupGrid(); | |
chart.draw(); | |
} | |
}); | |
} | |
}; | |
}); |
This file contains hidden or 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
<div ng-app='App'> | |
<div ng-controller='Ctrl'> | |
<p><button ng-click='change()'>Change Data</button></p> | |
<chart ng-model='data'> </chart> | |
</div> |
This file contains hidden or 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
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