简体   繁体   English

Google图表:无法读取未定义的属性“ 0”

[英]Google Charts: Cannot read property '0' of undefined

I cannot seem to get google charts working with JSON data. 我似乎无法让Google图表处理JSON数据。 I get this error: 'Cannot read property '0' of undefined.' 我收到此错误: “无法读取未定义的属性'0'。” The JSON response DOES have a JSON content type set. JSON响应确实设置了JSON内容类型。 I've looked around at similar questions but cannot seem to find any solution. 我环顾了类似的问题,但似乎找不到任何解决方案。

Javascript: Javascript:

google.load('visualization', '1', {
  packages: ['corechart']
});
google.setOnLoadCallback(get_data);

function get_data() {
  $.getJSON('/api?data=graphs', function(json) {
    var status = json.status;
    render_chart(status);
  });
}

function render_chart(status) {
  var status_chart = new google.visualization.DataTable(status);
  var options_status_chart = {
    lineWidth: 0,
    areaOpacity: 0.5
  }
}

JSON Response: JSON响应:

{
  "status": {
     "cols": [{
        "type": "string",
        "label": "Date - Time",
        "id": "dt_metric"
     }, {
        "type": "number",
        "label": "Status",
        "id": "s_metric"
     }],
     "rows": [{
        "c": [{
           "v": "2016\/1\/5 - 09:30"
        }, {
           "v": 0
        }]
     }, {
        "c": [{
           "v": "2016\/1\/5 - 10:00"
        }, {
           "v": 1
            }]
         }]
    }
}

There is something wrong with your JSON response, a missing curly brace at the end of the file. JSON响应有问题,文件末尾缺少大括号。 That's why it's not being parsed as proper JSON. 这就是为什么未将其解析为正确的JSON的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法读取未定义的Google图表的属性“ DataTable” - Cannot read property 'DataTable' of undefined google charts 无法读取谷歌图表中未定义的属性“计数” - cannot read property 'count' of undefined in google charts 创建视图时,Google图表会抛出“无法读取未定义的属性'1'” - Google Charts throws “cannot read property '1' of undefined” when creating a view Google Charts API:无法读取未定义的属性“ toArrays” - Google Charts API : Cannot read property 'toArrays' of undefined JS-Google图表-无法读取未定义的属性'getChartLayoutInterface' - JS - Google charts - Cannot read property 'getChartLayoutInterface' of undefined 无法读取 React with Google 图表中未定义的属性“推送” - Cannot read property 'push' of undefined in React with Google charts 无法读取Google Geo Charts中未定义的属性'arrayToDataTable' - Cannot read property 'arrayToDataTable' of undefined at Google Geo Charts 无法读取媒体资源Google图表 - Cannot read property google charts 谷歌图表错误:无法读取未定义的属性“长度”; Google图表中的调试错误 - Google charts error:Cannot read property 'length' of undefined; Debugging error in Google Charts 浮动图表:无法读取未定义的属性“插件” - flot charts: Cannot read property 'plugins' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM