Skip to content

Instantly share code, notes, and snippets.

@clouddueling
Last active December 21, 2015 07:19
Show Gist options
  • Save clouddueling/6270582 to your computer and use it in GitHub Desktop.
Save clouddueling/6270582 to your computer and use it in GitHub Desktop.
highcharts directive
'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