Gviz 可以选择使用 JSON 数据填充图表,因此,您可以使用 jquery 轻松地完成此操作,只需调用您的服务器以获取一组新数据,让它返回 JSON,然后将其传递给绘制函数你的图表。
你的 jquery/javascript 看起来像这样:
function drawMyChart(data) {
// stuff to draw chart using the contents of data
// data should be Gviz Data Table in JSON format
// your server needs to output this
var dt = new google.visualization.DataTable(data)
// rest of your stuff, just like standard gviz
}
function makeAjaxCall() {
$.ajax({
url: '/path/to/data/json',
sucess: drawMyChart(a),
dataType: 'json' // this is important, have it interpreted as json
});
}
// html somewhere
<input type='button' onclick='makeAjaxCall()'>Go</input>
关于正确格式化 JSON 响应,有几个库可以帮助您,尽管我不知道您提到的语言中有什么具体内容。这里有一个python http://code.google.com/p/google-visualization-python/例如。
如果您遇到困难,可以将所有条目转储到数组中,如下所示:
[[name, age],[john, 25],[paul, 20]]
and use google.visualization.arrayToDataTable http://code.google.com/apis/chart/interactive/docs/reference.html#google.visualization.arraytodatatable当它从服务器返回时将其解释为 JSON。
希望有帮助。