使用flt,mysql,php实时绘图 [英] Real time graphing with flot, mysql, php

查看:85
本文介绍了使用flt,mysql,php实时绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试绘制实时图形,因为我的mysql表不断插入值,例如从中引用的移动图形 http://kalanir.blogspot. com/2009/11/how-to-plot-moving-graphs-using-flot.html 该值实际上来自二氧化碳传感器,该传感器使用位置为 id co2 值更新表格的值.我将她的Math.Random更改为以下代码:

I'm trying to draw a real time graph as my mysql table is constantly being inserted with values, like a moving graph referenced from http://kalanir.blogspot.com/2009/11/how-to-plot-moving-graphs-using-flot.html The values actually come from a carbon dioxide sensor which updates the value of the table with co2 values with positions id. I changed her Math.Random to the code below:

<?php $result = mysql_query("SELECT * FROM node1 ORDER BY id DESC LIMIT 1")or die(mysql_error());?>
<?php $row = mysql_fetch_array( $result );?>

var j = "<?php echo $row['co2'];?>";
var next = "<?php echo $row['id'];?>";

for (var i = 0; i < this.xscale - 1; i++) 
{  
  this.array[i] = [i,this.array[i+1][1]];  // (x,y)  
}   
this.array[this.xscale - 1] = [this.xscale - 1,j]; 

但是,当我运行此代码时,第一个值更改,此后它保持不变,即使表的最后一行正在更新. 我听说这是因为在php中,服务器仅被轮询了一次.因此,我只能不断读取第一个数据.有什么方法可以使图形更新到表的最后一个值?用ajax?

However, when i run this code, the first value changes, after which it remains constant, even though the last row of the table is being updated. I heard it is because in php, the server is only polled once. Therefore i only get a constant reading of the first data. Is there any way in which i can make the graph update to the last value of the table? with ajax?

感谢您的帮助

推荐答案

是的,您可以使用定期刷新(轮询) 或者 HTTP流.

Yes, you can use Periodic refresh (Polling) or HTTP Streaming.

请注意,这两个选项对带宽的要求都很高.

Note that both of these options can be quite bandwidth demanding.

这篇关于使用flt,mysql,php实时绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆