Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions angular-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@
chartColors: '=?',
chartClick: '=?',
chartHover: '=?',
chartDatasetOverride: '=?'
chartDatasetOverride: '=?',
chartForceUpdate: '=?'
},
link: function (scope, elem/*, attrs */) {
if (useExcanvas) window.G_vmlCanvasManager.initElement(elem[0]);
Expand All @@ -118,7 +119,7 @@
scope.$watch('chartData', watchData, true);
scope.$watch('chartSeries', watchOther, true);
scope.$watch('chartLabels', watchOther, true);
scope.$watch('chartOptions', watchOther, true);
scope.$watch('chartOptions', watchOptions, true);
scope.$watch('chartColors', watchOther, true);
scope.$watch('chartDatasetOverride', watchOther, true);
scope.$watch('chartType', watchType, false);
Expand All @@ -139,7 +140,7 @@
var chartType = type || scope.chartType;
if (! chartType) return;

if (scope.chart && canUpdateChart(newVal, oldVal))
if (scope.chart && (canUpdateChart(newVal, oldVal) || scope.chartForceUpdate))
return updateChart(newVal, scope);

createChart(chartType, scope, elem);
Expand All @@ -156,6 +157,12 @@
createChart(chartType, scope, elem);
}

function watchOptions (newVal, oldVal) {
if (isEmpty(newVal)) return;
if (angular.equals(newVal, oldVal)) return;
updateChartOption(newVal, scope)
}

function watchType (newVal, oldVal) {
if (isEmpty(newVal)) return;
if (angular.equals(newVal, oldVal)) return;
Expand Down Expand Up @@ -352,6 +359,18 @@
cvs.onmousemove = scope.chartHover ? getEventHandler(scope, 'chartHover', true) : angular.noop;
}

function updateChartOption(values,scope) {
if (values) {
Object.keys(values).forEach((key) => {
if (scope.chart.options[key]) {
scope.chart.options[key] = values[key]
}
})
scope.chart.update('quiet');
scope.$emit('chart-update', scope.chart);
}
}

function updateChart (values, scope) {
if (Array.isArray(scope.chartData[0])) {
scope.chart.data.datasets.forEach(function (dataset, i) {
Expand Down