We are currently graphing our load data using jpgraph, example found here: http://www.txohosting.com/ercot/joel.php
Now, I wish to be able to view archived data from the sql database. The data is store such as this:
ercotload = 3838848 (just a value)
datetime = 2004-07-06 00:30:01
that is the format.
As of right now, the page above is using this:
$result = mysql_query("SELECT ercotload,datetime FROM ercotload WHERE datetime between '2004-07-06 00:00:00' AND '2004-07-06 23:59:59';") or die("Query failed");
to grab the data from a particular day & time. I wish to use a drop down to select a range.
I have no idea how to do this, and hope someone could help. I could post the entire php file I use if helpful.
Can someone please help me how to figure this out.
<php><?php
// A medium complex example of JpGraph
// Note: You can create a graph in far fewwr lines of code if you are
// willing to go with the defaults. This is an illustrative example of
// some of the capabilities of JpGraph.
include ("../../include/jpgraph.php");
include ("../../include/jpgraph_line.php");
include ("../../include/jpgraph_bar.php");
$month=array("Jan","Feb","Mar","Apr","Maj","Jun","Jul","Aug","Sep","Okt","Nov","Dec");
// Create some datapoints
// for($i=0; $i<$steps; ++$i) {
$databary = "";
$db = mysql_connect("db", "root", "*") or die("Could not connect");
mysql_select_db("ercot") or die("Could not select database");
$result = mysql_query("SELECT ercotload,datetime FROM ercotload WHERE datetime between '2002-06-19 03:00:00' AND '2002-06-19 11:00:00';") or die("Query failed");
$ii = 0;
global $ercotload;
while ($row = mysql_fetch_array($result)) {
$ercotload[$ii] = $row[0];
$datetime[$ii] = $row[1];
$ii++;
}
$datay = "";
for ($i=0; $i<700; ++$i) {
$exnow = explode(" ", $datetime[$i]);
$exnow = explode(":", $exnow[1]);
$time = $exnow[0].":".$exnow[1];
$databarx[] = $time;
$datay[$i]=$ercotload[$i];
}
// New graph with a background image and drop shadow
$graph = new Graph(550,500,"auto", -1);
// $graph->SetBackgroundImage("tiger_bkg.png",3);
$graph->SetShadow();
// Use text X-scale so we can text labels on the X-axis
$graph->SetScale("textlin");
// Y2-axis is linear
$graph->SetY2Scale("lin");
// Color the two Y-axis to make them easier to associate
// to the corresponding plot (we keep the axis black though)
$graph->yaxis->SetColor("black","red");
$graph->y2axis->SetColor("black","orange");
$today = date("F j, Y, g:i a");
// Set title and subtitle
$graph->title->SetFont(FF_VERDANA,FS_NORMAL,28);
$graph->title->Set("ERCOT Load");
$graph->subtitle->Set("$today");
// Use built in font (don't need TTF support)
$graph->title->SetFont(FF_FONT1,FS_BOLD);
// Make the margin around the plot a little bit bigger then default
$graph->img->SetMargin(40,140,40,80);
// Slightly adjust the legend from it's default position in the
// top right corner to middle right side
$graph->legend->Pos(0.03,0.5,"right","center");
// Display every 60:th tickmark
$graph->xaxis->SetTextTickInterval(30);
// Label every 1:nd tick mark
$graph->xaxis->SetTextLabelInterval(2);
// Setup the labels
$graph->xaxis->SetTickLabels($databarx);
$graph->xaxis->SetLabelAngle(90);
//$graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,11);
//$graph->xaxis->SetTickLabels($labels);
//$graph->xaxis->SetLabelAngle(45);
// Create a red line plot
$p1 = new LinePlot($datay);
$p1->SetColor("red");
$p1->SetLegend("Pressure");
// Create the bar plot
$b1 = new BarPlot($databary);
$b1->SetLegend("Temperature");
$b1->SetFillColor("orange");
// $b1->SetColor("green");
$b1->SetAbsWidth(8);
// Drop shadow on bars adjust the default values a little bit
// $b1->SetShadow("steelblue",2,2);
// The order the plots are added determines who's ontop
$graph->Add($p1);
$graph->AddY2($b1);
// Finally output the image
$graph->Stroke();
?>
</php>