AngularJs + Highcharts example
by amrutaJgtp
HTML
<html ng-app="myModule">
<title> Highcharts directive demo </title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
<script type="text/javascript" src="https://code.highcharts.com/highcharts.js"></script>
<script type="text/javascript" src="https://code.highcharts.com/modules/exporting.js"></script>
<body ng-controller="myController">
<hc-chart options="chartOptions">Placeholder for generic chart</hc-chart>
</body>
</html>
JavaScript
angular.module('myModule', [])
// Directive for generic chart, pass in chart options
.directive('hcChart', function () {
return {
restrict: 'E',
template: '<div></div>',
scope: {
options: '='
},
link: function (scope, element) {
Highcharts.chart(element[0], scope.options);
}
};
})
.controller('myController', function ($scope) {
// Sample options for first chart
$scope.chartOptions = {
title: {
text: 'Temperature data'
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
};
});