tags:

views:

27

answers:

0

Hi guys, i've finally zoomed down on how to dynamically plot graphs using flot. its been a journey. currently i've got function draw() on setInterval for every 5 seconds. My Mysql table is constantly updating, and my phpfile (response.php) echos the last value. The php looks like this:

//Get the last row $result = mysql_query("SELECT * FROM node1 ORDER BY id DESC LIMIT 1")or die(mysql_error()); $row = mysql_fetch_array( $result ); echo $row['humidity'];

My draw function, however, var array;
var xscale = 100;
var max = 0;

//this function does the plotting
function draw() {
$.ajax({
url: 'response.php', success: function(data) { for (var i = 0; i < this.xscale - 1; i++) {
this.array[i] = [i,this.array[i+1][1]]; // (x,y)
}
//alert(data); this.array[this.xscale - 1] = [this.xscale - 1,data];
} });

$.plot($("#graphdiv"), [  
{  
  label: "Y vs X",  
  data: this.array, 
  lines: { show: true, fillColor: "rgba(249, 28, 61,0.3)",lineWidth: 3.5 },  
  //points: { show: true },
  color:"rgb(200,20,30)" , 
  threshold: { below: 0.5, color: "orange" },
}  
],  
{  
  xaxis: 
  {  
    //ticks: generateTicks(),  
    min: 0  
  },  
  yaxis: 
  {  
   //ticks: [0 , 0.2, 0.4, 0.6, 0.8, 1.0, 1.2],  
    min: 0  
  },  
  //placing a grid  
  grid: 
  {  
    show: true,  
    color: '#474747',  
    tickColor: '#474747',  
    borderWidth: 1,  
    autoHighlight: true,  
    mouseActiveRadius: 2  
  }  
});  

}
as you can see there is an alert() cancelled out. alert tells me the correct value at the time interval. My problem is, the graph wont move! i've no clue why! the data points are not accepting any incoming data, they're just as initialized. any help would be appreciated