谷歌图表 - 未捕获的错误:不是数组 [英] Google Chart - uncaught error: not an array

查看:85
本文介绍了谷歌图表 - 未捕获的错误:不是数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个生成google图表数据并以json编码格式返回的php脚本。它使用jQuery $ .get()方法加载到Google图表中。当我将返回数据传递给谷歌 arrayToDataTable 这样的功能:

  var googleChartData = google.visualization.arrayToDataTable(chartData); 

我得到这个错误:

< img src =https://i.stack.imgur.com/11qLo.pngalt =

因此,我所做的是我倾倒了我的变量 chartData 的值,并得到以下结果:


因此,我所做的是将这些数据从控制台窗口复制到



  var googleChartData = google.visualization.arrayToDataTable([[Date> arrayToDataTable  0001 \ / 102 \ / 0可用,0001 \ / 102\ / 0不可用,0001 \ / 102\ / 1可用,0001 \ / 102\ / 1 Unavailable],[02 \ / 10 \ / 2013,0,1,110,11],[03 \ / 10 \ / 2013,0,1,189,11],[04 \\ \\ / 10\ / 2013\" ,0,1,189,11],[ 06\ / 10\ / 2013​​,0,1,189,10],[ 07\ / 10\ / 2013​​,0 ,1,187,10],[ 08\ / 10\ / 2013​​,186,11,0,1] ,[ 09\ / 10\ / 2013​​,186,11,0,1],[ 10\ / 10\ / 2013​​,0,1,186,11],[11\ / 10 \ / 2013\" ,0,1,204,11],[ 13\ / 10\ / 2013​​,0,1,204,11]]); 

现在图表呈现(如预期的那样,因为我的php脚本返回的数据是正确的):





这有点奇怪;是否有人知道为什么图表在从变量加载时不起作用?解析方案

解决方案

arrayToDataTable 这样的行:

  var googleChartData = google.visualization.arrayToDataTable($。parseJSON(chartData )); 

感谢这篇文章: https://stackoverflow.com/a/9420583/2332336


I have a php script that generates the google chart data and returns it in json encoded format. It's loaded into google chart using jQuery $.get() method. When I pass the return data to the google "arrayToDataTable" function like this:

var googleChartData = google.visualization.arrayToDataTable(chartData);

I get this error:

So, what I did was I dumped the value of my variable "chartData" and I got the following:

So, what I did was, copy this data from console window into the "arrayToDataTable" function manually like this:

var googleChartData = google.visualization.arrayToDataTable([["Date Range","0001\/102\/0 Available","0001\/102\/0 Unavailable","0001\/102\/1 Available","0001\/102\/1 Unavailable"],["02\/10\/2013",0,1,110,11],["03\/10\/2013",0,1,189,11],["04\/10\/2013",0,1,189,11],["06\/10\/2013",0,1,189,10],["07\/10\/2013",0,1,187,10],["08\/10\/2013",186,11,0,1],["09\/10\/2013",186,11,0,1],["10\/10\/2013",0,1,186,11],["11\/10\/2013",0,1,204,11],["13\/10\/2013",0,1,204,11]]);

Now the chart renders (as expected, because the returned data from my php script is correct):

This is a bit bizarre; does any one know why the chart doesn't work when it's loaded from the variable?

解决方案

I've solved it by changing arrayToDataTable line like this:

var googleChartData = google.visualization.arrayToDataTable($.parseJSON(chartData));

Thanks to this post: https://stackoverflow.com/a/9420583/2332336

这篇关于谷歌图表 - 未捕获的错误:不是数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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