Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: google.visualization.arrayToDataTable is not a function

Tags:

javascript

I am trying to copy this example.

The example has this definition:

var data = google.visualization.arrayToDataTable([
['a', 14],
['b', 47],
['c', 80],
['d', 55],
['e', 16],
['f', 90],
['g', 29],
['h', 23],
['i', 58],
['j', 48]
// Treat first row as data as well.
  ], true);

I have replaced the first parameter with my variable buckets which is also an array of length-2 arrays. I'm getting the following error which makes no sense:

TypeError: google.visualization.arrayToDataTable is not a function

Even if buckets is malformed(which I don't think it is) how could that change the identity of arrayToDataTable? It's still a function!

like image 955
jaynp Avatar asked Aug 28 '13 05:08

jaynp


2 Answers

I understand that this is a very late answer, but just in case anybody else comes across this question I'll post this here. I had the same error, but then I checked out how Google Developers did it on their jsfiddle.

Replace this:

<script src="//www.google.com/jsapi"></script>

With this:

<script type="text/javascript" src="https://www.google.com/jsapi?autoload= 
{'modules':[{'name':'visualization','version':'1.1','packages':
['corechart']}]}"></script>

And then delete this line:

google.load("visualization", "1", {packages:["corechart"]});

And of course, make sure that you run it on a server.

like image 122
abagh0703 Avatar answered Oct 31 '22 23:10

abagh0703


Looks like you haven't loaded the Google Visualization API. Have you got this somewhere?

<script src="//www.google.com/jsapi"></script>
<script>
    google.load('visualization', '1', {packages: ['imagechart']});
</script>

FYI - I got this by clicking the Edit HTML button on the example page

like image 36
Phil Avatar answered Oct 31 '22 22:10

Phil