我有试图为谷歌图表构建二维数组的当前代码。
但是我得到一个无效的二维数组错误。
我究竟做错了什么?先感谢您
//Request data
$.getJSON(api,function(data){
//Init final array for data
var finalData = [["SessionLength"]];
//Iterate over results
for (var key in data){
//Get the key pair
var keyPair = [key, parseInt(data[key])];
//Add to array
finalData.push(keyPair);
}
// Create the data table.
var data = google.visualization.arrayToDataTable(finalData);
// Set chart options
var options = {'title':'Average session length',
'width':400,
'height':400};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
});
这是 JSON
{"2013-8-5":"13.5","2013-7-29":"19.7","2013-8-4":"12.2","2013-8-3":"14.1","2013-8-2":"10.1","2013-7-31":"15.1","2013-7-30":"17.4","2013-8-6":"16.0","2013-8-1":"15.0"}