[英]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.