ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Plotting live data in real time over 24 hours.
Posted by Harlow Pinson on Aug-19-2011 01:03
Hi Peter.

I've run into a problem and wonder if you could offer some advice.

My application is a line chart, with a new value plotted each hour over 24 hours.  A data point is added hourly to the db, just before I chart it.

I find that if all elements of the array exist (i.e. 24 hours) the chart will render.

But if values are missing (ie. the 9:00 value has not yet been written to the db) the chart will not render.

Suggestions?  Here is an outline of my PHP code approach:

<?php

// SQL Query.
$result = mssql_query("SELECT timestamp, field1 FROM table WHERE timestamp LIKE '$today%'");

// Assign field values from query results to an array.
while($row = mssql_fetch_array($result))
  {
  $myarray[] = $row['field1'];
  }


# The data for the line chart
$data0 = array($myarray[0],$myarray[1],$myarray[2],$myarray[3],$myarray[4],$myarray[5],$myarray[6],$myarray[7],$myarray[8],$myarray[9],$myarray[10],$myarray[11],$myarray[12],$myarray[13],$myarray[14],$myarray[15],$myarray[16],$myarray[17],$myarray[18],$myarray[19],$myarray[20],$myarray[21],$myarray[22],$myarray[23]);

// ... formatting removed for this example.

# Add a line layer to the chart
$layer = $c->addLineLayer2();

# Set the line width to 3 pixels
$layer->setLineWidth(3);

# Add the three data sets to the line layer, using circles, diamands and X shapes as
# symbols
$dataSetObj = $layer->addDataSet($data0, 0xff0000, "Flow Diverted (CFS)");
$dataSetObj->setDataSymbol(CircleSymbol, 9);

# Output the chart
header("Content-type: image/png");
print($c->makeChart2(PNG));


?>

  Re: Plotting live data in real time over 24 hours.
Posted by Peter Kwan on Aug-19-2011 23:50
Hi Harlow,

There are many reasons why the chart cannot be rendered. For example, your PHP may be configured to output warning or error messages when you use undefined values. (The $myarray[15] is undefined if you only have 9 values, but your code use it anyway to construct the $data0 array.)

If I were you, I would use:

$data0 = $myarray;

.....

$c->xAxis->setLinearScale(0, 24, 4);

(Note that the above code assumes $myarray exists. In your current code, there is no guarantee that $myarray exists. You may want to add one more line "$myarray=array();" at the start of your code to make sure $myarray exists.

Hope this can help.

Regards
Peter Kwan