Skip to content

Commit

Permalink
Add support for javascript in highchart configuration
Browse files Browse the repository at this point in the history
fixes rootux#4
  • Loading branch information
stissot committed Jun 6, 2013
1 parent d4c3898 commit 90a9877
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion sample/views/main.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div>
<chart value='{{basicAreaChart}}' type="area" height="400">
<chart value='basicAreaChart' type="area" height="400">
</chart>
</div>
11 changes: 7 additions & 4 deletions src/directives/highchart.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ angular.module('chartsExample.directives',[])
return {
restrict: 'E',
template: '<div></div>',
scope: {
chartData: "=value"
},
transclude:true,
replace: true,

Expand All @@ -18,16 +21,16 @@ angular.module('chartsExample.directives',[])
width: attrs.width || null
}
};

//Update when charts data changes
scope.$watch(function() { return attrs.value; }, function(value) {
if(!attrs.value) return;
scope.$watch(function() { return scope.chartData; }, function(value) {
if(!value) return;
// We need deep copy in order to NOT override original chart object.
// This allows us to override chart data member and still the keep
// our original renderTo will be the same
var deepCopy = true;
var newSettings = {};
$.extend(deepCopy, newSettings, chartsDefaults, JSON.parse(attrs.value));
$.extend(deepCopy, newSettings, chartsDefaults, scope.chartData);
var chart = new Highcharts.Chart(newSettings);
});
}
Expand Down

0 comments on commit 90a9877

Please sign in to comment.