[英]Ajax Google Visualization API Gauge with jquery
I am looking to create a dashboard gauge that updates via ajax. 我希望创建一个通过ajax更新的仪表板仪表。 Below is the code I have.
以下是我的代码。 I have the ajax code but just am unsure on how to update the gauge.
我有ajax代码,但我不确定如何更新仪表。 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);
}
ajax code... ajax代码......
foreach($obj->sensor as $unit) { if ($unit->label=="Temp") { echo $unit->tempf." F"; foreach($ obj-> sensor as $ unit){if($ unit-> label ==“Temp”){echo $ unit-> tempf。“F”; } }
}}
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.