阿贾克斯谷歌可视化API计与jQuery [英] Ajax Google Visualization API Gauge with jquery
问题描述
我期待创建仪表盘仪表通过AJAX的更新。下面是code我有。我有AJAX code,但只是我不能确定如何更新计。有什么建议?
I am looking to create a dashboard gauge that updates via ajax. Below is the code I have. I have the ajax code but just am unsure on how to update the gauge. Any suggestions?
google.load('visualization', '1', {packages:['gauge']});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Label');
data.addColumn('number', 'Value');
data.addRows(1);
data.setValue(0, 0, 'Tempature');
data.setValue(0, 1, 76);
var chart = new google.visualization.Gauge(document.getElementById('liveTempChart'));
var options = {width: 340, height: 130, redFrom: 90, redTo: 100,
yellowFrom:75, yellowTo: 90, minorTicks: 5};
chart.draw(data, options);
}
阿贾克斯code ...
ajax code...
的foreach($ obj->传感器$单位){ 如果($单位 - >标签==温度){ 回声$单位 - > tempfF。 } }
foreach($obj->sensor as $unit) { if ($unit->label=="Temp") { echo $unit->tempf." F"; } }
推荐答案
您可以使用同样的code进行更新了。您需要创建一个新的数据表实例,并再次呼吁图表的绘制函数(非常类似于你如何更新,在第一时间)。
You can use the same kind of code for update too. You need to create a new data table instance and call the draw function of the chart again (very similar to how you updated the first time).
var data = new google.visualization.DataTable();
data.addColumn('string', 'Label');
data.addColumn('number', 'Value');
data.addRows(1);
data.setValue(0, 0, 'Tempature');
data.setValue(0, 1, 76);
chart.draw(data, options);
这篇关于阿贾克斯谷歌可视化API计与jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!