<?
include ("src/jpgraph.php");
include ("src/jpgraph_bar.php");
include ("src/jpgraph_line.php");
include("common.php");
$tao = $_GET['tao']; //ตัวแปรที่ผม GET ค่าเข้ามาแล้วใช้งานไม่ได้
$pin = $_GET['pin'];
//$tao = 1750; // ตัวแปรที่ผมกำหนดค่าให้เหมือนกับค่าที่ GET เข้ามา แต่ตัวแปรนี้ใช้งานได้
//$pin = 1770;
$sql = "select * from graph where id between '$tao' and '$pin' order by id asc "; //แทรกในคำสั่ง sql
$qry = mysql_query($sql);
$time = array();
while($rsl = mysql_fetch_array($qry)) {
$time[] = substr($rsl[time_date],0,5);
}
// ------------------ WL ------------------------
$sql = "select * from graph where id between '$tao' and '$pin' order by id asc ";
$qry = mysql_query($sql);
$wl = array();
while($rsl = mysql_fetch_array($qry)) {
$wl[] = $rsl[wl];
}
//--------------Size of the overall graph--------
$width=450;
$height=250;
// ---------Create the graph and set a scale.
// These two calls are always required-------------
$graph = new Graph($width,$height);
$graph->SetScale('textlin');
// ---------Setup margin and titles-------------
$graph->SetMargin(40,20,20,50);
$graph->title->Set('Water Level');
$graph->title->SetColor('#33CC00');
$graph->subtitle->Set('(March 12, 2008)');
$graph->subtitle->SetColor('#33CC00');
$graph->xaxis->title->Set('Time()');
$graph->xaxis->title->SetColor('red');
$graph->xaxis->title->SetMargin(14);
$graph->yaxis->title->Set('Water Level (m)');
$graph->yaxis->title->SetColor('blue');
// ----------Create the linear plot-----------
$lineplot=new LinePlot($wl);
$lineplot->SetColor( '#336600' );
//$lineplot->SetWeight( 2 ); // Two pixel wide
$lineplot->mark->SetType(MARK_IMG_DIAMOND,5,0.2,4);
$lineplot->mark->SetColor('blue');
$lineplot->mark->SetFillColor('red');
//$lineplot->value->Show();
//------- Enable X and Y Grid-------
$graph->xgrid->Show();
$graph->xgrid->SetColor('[email protected]');
$graph->xgrid->SetLineStyle('dashed');
$graph->ygrid->SetColor('[email protected]');
$graph->ygrid->SetLineStyle('dashed');
//$graph->yaxis->SetColor('blue');
//$graph->xaxis->SetColor('blue');
$graph->xaxis->SetTickLabels($time);
$graph->xaxis->SetFont(FF_COURIER,FS_NORMAL,8);
$graph->xaxis->SetLabelAngle(90);
//---------- Add the plot to the graph-------
$graph->Add($lineplot);
//---------- Display the graph--------------
$graph->Stroke();
mysql_close($con);
?>
Tag : PHP, MySQL, HTML/CSS, JavaScript, Ajax, jQuery