刷新动态可视化谷歌 [英] Refresh Google Visualization on the fly
问题描述
我目前正在创建通过谷歌可视化图表谷歌,我希望能够刷新/更新上的一个按钮点击此图表。我已经尝试了很多不同的方法可以做到这一点,但它没有一个作品,所以我正在寻找任何建议,任何人都可以做到的。我现在的平台是ASP.net(用C#)和谷歌的东西是用JavaScript编写/ jQuery的(显然)。谢谢!
I am currently creating a google chart via google visualization and I want to be able to refresh/update this chart on a button click. I've tried a lot of different ways to do this but none of it works so I'm looking for any suggestions that anybody can make. My current platform is ASP.net (with C#) and the google stuff is written in javascript/jquery (obviously). Thanks!
推荐答案
Gviz具有填充JSON数据图表选项,因此,您可以通过拨打电话到您的服务器,以获得一个新的使用jQuery做到这一点很容易够简单组数据,让它返回JSON,然后传送到你的绘制图表的功能。
Gviz has the option to populate charts with JSON data, so, you can do this with jquery easily enough simply by making a call to your server to get a new set of data, having it return JSON, then passing this to a function that draws your charts.
您的jQuery / JavaScript的西港岛线是这个样子:
Your jquery/javascript wil look something like this:
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响应,有一对夫妇库都来帮助你,虽然我不知道具体在你提到的语言什么。这里有一个在蟒蛇例如
如果您有困难,你可以转储所有条目的数组如下:
If you're struggling, you can just dump out all of your entries in an array as follows:
[[name, age],[john, 25],[paul, 20]]
和使用<一个href=\"http://$c$c.google.com/apis/chart/interactive/docs/reference.html#google.visualization.arraytodatatable\"相对=nofollow> google.visualization.arrayToDataTable 国米preT它,当它到达从您的服务器为JSON回来了。
and use google.visualization.arrayToDataTable to interpret it when it arrives back from your server as JSON.
希望有所帮助。
这篇关于刷新动态可视化谷歌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!