Last active
December 21, 2015 07:19
-
-
Save clouddueling/6270582 to your computer and use it in GitHub Desktop.
highcharts 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
'use strict'; | |
angular.module('highcharts',[]) | |
.directive('chart', function () { | |
return { | |
restrict: 'E', | |
scope: { | |
data: "=" | |
}, | |
replace: true, | |
template: "<div></div>", | |
transclude: true, | |
link: function (scope, element, attrs) { | |
var chartsDefaults = { | |
chart: { | |
renderTo: element[0], | |
type: attrs.type || null, | |
height: attrs.height || null, | |
} | |
}; | |
var drawChart = function() { | |
var newSettings = {}; | |
angular.extend(newSettings, chartsDefaults, scope.data); | |
var chart = new Highcharts.Chart(newSettings); | |
}; | |
// Highcharts has to be redrawn everytime there's new data. | |
scope.$watch('data', function(value) { | |
if(!value) | |
return; | |
drawChart(); | |
}, true); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment