How to integrate Google charts as an AngularJs directive?

前端 未结 4 1808
一生所求
一生所求 2021-02-01 05:36

There are some examples of integrating Google charts as an AngularJs directive.

Like this one: http://plnkr.co/edit/YzwjuU?p=preview

Update: I w

4条回答
  •  一生所求
    2021-02-01 06:22

    I was having periodic trouble in Angular with the google chart API not being loaded on time to receive the data from a $http fetch. The data came first sometimes (not always), and then the usage of it in the callback would fail with "google.visualization.DataTable is not a function"

    Inside the callback returning data:

    var dataTable = new google.visualization.DataTable(data);
    

    To solve it, I found in ng-google-chart.js that there was a promise called "googleChartApiPromise", so I injected it, and wrapped the refresh call in it:

    googleChartApiPromise.then(function() {
        refreshCharts();
    });
    

    This seems to solve the problem.

提交回复
热议问题