Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Charts API: new google.visualization.Table() - Uncaught TypeError: undefined is not a function

I have copied the Google Code example into a php script however I am getting the error "undefined is not a function"

it is happening specifically on this line:

var table = new google.visualization.Table(document.getElementById('table_sort_div'));

It appeats that the Table function does not exist???

I have copied the code directly from Googles Code examples so I can't understand what I have done wrong... I'm tending to believe that there is an issue with the example but I'm gonna assume I'd make a mistake before google would?

Code was copied directly from: http://code.google.com/apis/chart/interactive/docs/examples.html#interaction_example

like image 794
php-b-grader Avatar asked Aug 05 '11 22:08

php-b-grader


1 Answers

You need to wait for the scripts to load. For example:

  // Load the Visualization API and the piechart package.
  google.load('visualization', '1.0', {'packages':['table']});

  // Set a callback to run when the Google Visualization API is loaded.
  google.setOnLoadCallback(drawChart);

  function drawChart() {
       var table = new google.visualization.Table(document.getElementById('table_sort_div'));
  }

should work, because the scripts have been loaded. A better table reference here

like image 190
Joe Avatar answered Oct 07 '22 11:10

Joe