doujing2497 2013-10-16 10:04
浏览 22
已采纳

谷歌图表 - 未捕获的错误:不是数组

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:

enter image description here

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

enter image description here

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

enter image description here

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

  • 写回答

1条回答 默认 最新

  • dongzhun8449 2013-10-16 10:33
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False