Randomly getting the error "TypeError: google.visualization.DataTable is not a constructor"

47 views
Skip to first unread message

alex2196

unread,
Jul 28, 2020, 3:50:18 AM7/28/20
to Google Visualization API
Till 27th july 2020, code was working file. (more than 2 years)
suddenly it started giving the above error randomly.
More than 50% i'm getting above error,
but sometimes code work totally fine , chart and tables loads up properly and no error...

can anyone help me please...

<script type="text/javascript" src="https://www.google.com/jsapi"></script>

<script type="text/javascript">
    google.load('visualization', '1.1', {packages: ['corechart', 'table']});
</script>


 $scope.loadChart = function (gdata) {
            var data = new google.visualization.DataTable();
            data.addColumn('datetime', 'Date Time');
            data.addColumn({type: 'string', role: 'annotation'});
            var datatype = 'number';
            var ColLength = gdata[0].length;
            var fullLength = gdata.length;

...
...

...

Daniel LaLiberte

unread,
Jul 28, 2020, 10:18:05 AM7/28/20
to Google Visualization API
Hi Alex,

Since you are calling your loadChart independent of whether google.load is done loading, then sometimes it won't be done.  You need to use one of the callback mechanisms documented here:   https://developers.google.com/chart/interactive/docs/basic_load_libs#callback  

Also, please switch to using the new loader, also documented in that same page.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/fb37b6a6-1b30-4994-9985-7b0e87881bafo%40googlegroups.com.


--

alex2196

unread,
Jul 29, 2020, 7:43:21 AM7/29/20
to Google Visualization API
Hi Daniel,
Thanks....

actually i'm using angularjs in php to load the google visualization charts, and the whole code was working from years by now and suddenly error popped up.

due to angular js i have never used google callback command.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.

Daniel LaLiberte

unread,
Jul 29, 2020, 11:00:34 AM7/29/20
to Google Visualization API
Hi Alex,

The angularjs component you are using should be fixed to load Google Charts properly.  That may take time for someone (any idea who?) to implement.   In the meantime, you should be able to add a timeout loop to your code before you start making calls to the Google Charts functions.   Something like this:

  function maybeDrawChart() {
    if (!window.google || !google.visualization || !google.visualization.DataTable) {
      setTimeout(maybeDrawChart, 2000);
      return;
    }
    // DataTable has been defined, so now we can proceed to draw the chart.
    ....
  }
  setTimeout(maybeDrawChart, 1000);

To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/0dbb7c60-1581-43d8-be76-8fd523f42b4bo%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages