Skip to content

Commit 90a9877

Browse files
committed
Add support for javascript in highchart configuration
fixes rootux#4
1 parent d4c3898 commit 90a9877

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

sample/views/main.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<div>
2-
<chart value='{{basicAreaChart}}' type="area" height="400">
2+
<chart value='basicAreaChart' type="area" height="400">
33
</chart>
44
</div>

src/directives/highchart.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ angular.module('chartsExample.directives',[])
66
return {
77
restrict: 'E',
88
template: '<div></div>',
9+
scope: {
10+
chartData: "=value"
11+
},
912
transclude:true,
1013
replace: true,
1114

@@ -18,16 +21,16 @@ angular.module('chartsExample.directives',[])
1821
width: attrs.width || null
1922
}
2023
};
21-
24+
2225
//Update when charts data changes
23-
scope.$watch(function() { return attrs.value; }, function(value) {
24-
if(!attrs.value) return;
26+
scope.$watch(function() { return scope.chartData; }, function(value) {
27+
if(!value) return;
2528
// We need deep copy in order to NOT override original chart object.
2629
// This allows us to override chart data member and still the keep
2730
// our original renderTo will be the same
2831
var deepCopy = true;
2932
var newSettings = {};
30-
$.extend(deepCopy, newSettings, chartsDefaults, JSON.parse(attrs.value));
33+
$.extend(deepCopy, newSettings, chartsDefaults, scope.chartData);
3134
var chart = new Highcharts.Chart(newSettings);
3235
});
3336
}

0 commit comments

Comments
 (0)