GrantMStevens / amCharts-Angular

Angular directive for amCharts library
Apache License 2.0
63 stars 39 forks source link

Load chart data with $http #5

Closed erikramalho closed 9 years ago

erikramalho commented 9 years ago

Could you please document how to load $scope.options.data ($scope.amChartOptions) from $http? I'm requesting the data with a $http.get and assigning the result to it but the chart doesn't get updated.

$http({url:'example', method: 'GET'}).success(function (response) {$scope.amChartOptions.data = response;});

I've seen in the directive that you have some events... Could you give me a hand?

GrantMStevens commented 9 years ago

Are you rendering the chart before the http call is completed?

There arent any watchers in place to see if the data object changes, so it would be up to you to handle that. Your best best to do this would be to use the amCharts.updateData event. Something like this:

$http({url:'example', method: 'GET'}).success(function (response) {
    $scope.$broadcast('amCharts.updateData', response, 'MyChartId');
});

Make sure you are passing the id of the chart as the third argument. This will trigger the chart to reload itself with the new dataset.

I am going to try to find some time to build this directive out some more, which will include a watcher to detect changes in the data object and reload the chart accordingly. For now, your best bet is to use the event.