How to load JSON Data on google visualization Chart?

北城以北 提交于 2019-12-07 03:30:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!