如何在Google可视化图表上加载JSON数据? [英] How to load JSON Data on google visualization Chart?

查看:100
本文介绍了如何在Google可视化图表上加载JSON数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是谷歌可视化新手。我正在开发完整的信息中心,例如 Google完整信息中心示例

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'] .... ]);

现在我想从服务器加载数据。我创建了一个Json,如下所示:

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);

当我打开页面时,出现以下错误:Object#has no method'zg'at格式+ it,默认+ it,ui + it,controls + it,corechart + it.I.js:183

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 "

我在哪里错了? JSON格式不正确?

where am I wrong? JSON format is wrong?

推荐答案

您缺少新的关键字DataTable构造函数。它应该是:

You are missing the new keyword in the DataTable constructor. It should be:

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

这篇关于如何在Google可视化图表上加载JSON数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆