JSON => GoogleCharts格式 [英] JSON => GoogleCharts formatting

查看:180
本文介绍了JSON => GoogleCharts格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我拼命地试图让我的GoogleChart工作。这段代码总是引发错误:

  function drawChart()
{
var data = new google .visualization.DataTable();
data.addColumn('number','hour');
data.addColumn('number','TriggerCount');
var JsonManuallyEncoded ='{1:{1:01,2:4},2:{1:03,2:4},3:{1:04,2:48},4:{1: 05,2:59},5:{1:06,2:59},6:{1:07,2:87},7:{1:08,2:62},8:{1:09, 2:46},9:{1:10,2:61},10:{1:11,2:71},11:{1:12,2:54},12:{1:13,2: 61},13:{1:14,2:89},14:{1:15,2:58},15:{1:16,2:122},16:{1:17,2:108} ,17:{1:18,2:64},18:{1:19,2:50},19:{1:20,2:10},20:{1:21,2:18}}; '
data.addRows(JsonManuallyEncoded);


var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(data);}

Firefox控制台说:参数给addRows必须是一个数字或数组。
我怀疑JSON字符串的格式是不正确的,但我无法弄清楚出了什么问题。有人可以指出我的错误吗?这可能是微不足道的,但是我已经花了几个小时在...

解决方案

你看过 addRows ?但是您不应将行数据作为JSON编码字符串传递给 addRows ,您应该传递数组数组结构。我认为可能还有其他API函数来传递JSON字符串,所以我建议您阅读文档并查看示例。


I am desperately trying to get my GoogleChart working. This code always throws an error though:

        function drawChart() 
        { 
          var data = new google.visualization.DataTable(); 
          data.addColumn('number', 'hour'); 
          data.addColumn('number', 'TriggerCount'); 
          var JsonManuallyEncoded = '{1:{1:01,2:4},2:{1:03,2:4},3:{1:04,2:48},4:{1:05,2:59},5:{1:06,2:59},6:{1:07,2:87},7:{1:08,2:62},8:{1:09,2:46},9:{1:10,2:61},10:{1:11,2:71},11:{1:12,2:54},12:{1:13,2:61},13:{1:14,2:89},14:{1:15,2:58},15:{1:16,2:122},16:{1:17,2:108},17:{1:18,2:64},18:{1:19,2:50},19:{1:20,2:10},20:{1:21,2:18}};'
          data.addRows(JsonManuallyEncoded);


        var chart = new google.visualization.ColumnChart(document.getElementById('chart_div')); 
        chart.draw(data);}

The Firefox console says: "Argument given to addRows must be eiter a number or an array". I suspect that the format of the JSON string is not correct, but I cannot figure out what's wrong. Can somebody please identify my mistake? It's probably trivial but I am spending hours on this already...

解决方案

Have you looked at the documentation for addRows? but you should not pass the row data to addRows as a JSON encoded string, you should pass a array of arrays data structure. I think there may be other API functions for passing a JSON string so i recommend you to read the documentation and look at the examples.

这篇关于JSON => GoogleCharts格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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