How to load JSON data on a Google visualization diagram?

I am new to Google visualization. I am developing a full toolbar, for example a full screen toolbar

Following an example, I declare such data:

var data = google.visualization.arrayToDataTable([ ['CodiceCliente', 'Cliente', 'QtàO13', 'QtàO14','UM'], ['0000038893', 'Coop',300,350, 'CT'] .... ]); 

Now I want to download data from the server. I create Json like this:

 { "cols": [ {"id": "codiceCliente","label": "Cod. Cliente","type": "string"}, {"id": "clienteDesc","label": "Cliente","type": "string"}, {"id": "qtaO13","label": "Qtà O13","type": "number"}, {"id": "qtaO14","label": "Qtà O14","type": "number"}, {"id": "um","label": "UM","type": "string"} ], "rows": [ { "c": [ {"v": "0000038893"}, {"v": "Coop"}, {"v": "300"}, {"v": "350"}, {"v": "CT"} ] }, {.... }, ... ]} 

In the html page, I use this code to get data from the server:

  var jsonData = $.ajax({ url: "getJson.do", dataType:"json", async: false }).responseText; var data = google.visualization.DataTable(jsonData); 

When I open the page, I get this error: "Object # does not have the" zg "method in + it format, defaults to + it, ui + it, controls + it, corechart + it.I.js: 183"

Where am I mistaken? Is the JSON format incorrect?

+6
source share
1 answer

There is no new keyword in the DataTable constructor. It should be:

 var data = new google.visualization.DataTable(jsonData); 
+5
source

All Articles