错误Google LineChart与正确的(?)JSON格式 [英] Error Google LineChart with proper (?) JSON format
问题描述
对不起!我知道有几个(很多)关于JSON和google api的帖子。我读了他们,试图解决这个问题几天。如果我必须清除我的浏览历史,我会爆炸,开始一个新鲜的心态...
我真的可以使用一些帮助。任何和所有的帮助将不胜感激。
控制台错误打印:TypeError:b [le]不是函数
这是我的功能:$ {
function timeline(){
$ .post('NewQuery.php',function(data){
alert(data);
var data = new google.visualization.DataTable(JSON.parse(data));
var view = new google.visualization.DataView(data)
view.setColumns([0,2])
chart = new google.visualization.LineChart(document.getElementById('chart2'));
chart.draw(view );
});
}
这是JSON对象,我已格式化为它更清晰。
{
cols:[
{label:Dia ,type:date},
{label:Fruta,type:string},
{label:CostoTotal,type数字}
],
rows:[
{c:[{v:Dia(2014,3,9)},{v 新西兰},{v:2628}]},
{c:[{v:Dia(2014,3,18)},{v:Cerezos },{v:3200841}}},
{c:[{v:Dia(2014,3,23)},{v:Peras},{ v:113696}]},
{c:[{v:Dia(2014,3,1)},{v:Cerezos},{v :4294967295}]}
]
}
问题在于您的日期字符串,它们应该使用Date,而不是Dia。这是:
Dia(2014,3,9)
应该是这样的:
日期(2014, 9)
Sorry all!! I know there are several (many) post regarding JSON and google api. I read them all and tried fixing the problem for several days. I am going to explode if I have to clear my browsing history, again, to start with a "fresh" mind... I could really use some help. Any and all help would be greatly appreciated.
Console error prints : "TypeError: b[le] is not a function"
Here is my function:
function timeline() {
$.post('NewQuery.php', function ( data ) {
alert (data);
var data = new google.visualization.DataTable(JSON.parse(data));
var view = new google.visualization.DataView(data)
view.setColumns ([0,2])
chart = new google.visualization.LineChart(document.getElementById('chart2'));
chart.draw(view);
});
}
Here is the JSON object that is 'alerted'- I formatted it to make it more legible.
{
"cols":[
{"label":"Dia","type":"date"},
{"label":"Fruta","type":"string"},
{"label":"CostoTotal","type":"number"}
],
"rows":[
{"c":[{"v":"Dia(2014, 3, 9)"},{"v":"Kiwis"},{"v":2628}]},
{"c":[{"v":"Dia(2014, 3, 18)"},{"v":"Cerezos"},{"v":3200841}]},
{"c":[{"v":"Dia(2014, 3, 23)"},{"v":"Peras"},{"v":113696}]},
{"c":[{"v":"Dia(2014, 3, 1)"},{"v":"Cerezos"},{"v":4294967295}]}
]
}
The problem is with your date strings, they should use the word "Date", not "Dia". This:
"Dia(2014, 3, 9)"
should be this:
"Date(2014, 3, 9)"
这篇关于错误Google LineChart与正确的(?)JSON格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!