我目前正在使用以下 JSON 使用 Google Chart API 生成图表:
{
"cols":[
{
"id":"DateOfBirth",
"label":"Date of Birth",
"type":"string"
},
{
"id":"Number",
"label":"Number",
"type":"number"
},
{
"id":"Gender",
"label":"Gender",
"type":"string"
}
],
"rows":[
{
"c":[
{
"v":"F"
},
{
"v":"2012-08-07"
},
{
"v":"1"
}
]
},
{
"c":[
{
"v":"M"
},
{
"v":"1988-07-28"
},
{
"v":"1"
}
]
},
{
"c":[
{
"v":"F"
},
{
"v":"1990-05-05"
},
{
"v":"1"
}
]
}
]
}
但是,图表没有显示(它只显示为带有标题的白色画布)。我无法弄清楚我的 JSON 有什么问题。我还包含了用于呈现图表的代码:
// where json is the string literal
function drawChart(json) {
// Create the data table.
var data = new google.visualization.DataTable(json);
// Set chart options
var options = {'title':'Students',
'width':400,
'height':300,
'view': {'columns': [0,2]}};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.PieChart($('#chart_div')[0]);
chart.draw(data, options);
}
...我用 AJAX 调用将所有内容拼凑在一起。
$(function() {
$.ajax({
type: "GET",
url: localUrl,
success: function(data)
{
drawChart(data);
}
});
});
google.load('visualization', '1.0', {'packages':['corechart']});
我不太确定我哪里出错了。有人可以帮帮我吗?