问题
I'm new with google-visualization. I'm developing a full dashboard like google full dashboard example
Following the example I declare data like this:
var data = google.visualization.arrayToDataTable([
['CodiceCliente', 'Cliente', 'QtàO13', 'QtàO14','UM'],
['0000038893', 'Coop',300,350, 'CT'] .... ]);
Now I want to load data from server. I create a 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 html page i use this code to get data from 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 # has no method 'zg' at format+it,default+it,ui+it,controls+it,corechart+it.I.js:183 "
where am I wrong? JSON format is wrong?
回答1:
You are missing the new
keyword in the DataTable constructor. It should be:
var data = new google.visualization.DataTable(jsonData);
来源:https://stackoverflow.com/questions/22632705/how-to-load-json-data-on-google-visualization-chart