Closed davidjllo closed 7 years ago
I just had to figure this out as well and I think the right way to do this is to broadcast the right events to get the chart to redraw. You do this in two steps:
app.controller('myController', ['$scope', '$rootScope', function ($scope, $rootScope) {
...
$rootScope.$broadcast('amCharts.renderChart');
...
The available events that he is listening for are defined in amChartsDirective.js
var onAmChartsTriggerChartAnimate = $scope.$on('amCharts.triggerChartAnimate', function (event, id) {
if (id === $el[0].id || !id) {
chart.animateAgain();
}
});
var onAmChartsUpdateData = $scope.$on('amCharts.updateData', function (event, data, id) {
if (id === $el[0].id || !id) {
chart.dataProvider = data;
chart.validateData();
}
});
var onAmChartsValidateNow = $scope.$on('amCharts.validateNow', function (event, validateData, skipEvents, id) {
if (id === $el[0].id || !id) {
chart.validateNow(validateData === undefined ? true : validateData,
skipEvents === undefined ? false : skipEvents);
}
});
var onAmChartsRenderChart = $scope.$on('amCharts.renderChart', function (event, amChartOptions, id) {
if (id === $el[0].id || !id) {
chart.clear();
renderChart(amChartOptions);
}
});
I'm creating charts dynamically and trying changing data depending on a button group but cant find a way to reference the charts. Do I use its id?
trying to do this: chart.dataProvider = chartData[d]; chart.validateData(); chart.animateAgain();