我希望能够进行查询,从数据库中获取数字,并使用 JpGraph 在折线图上呈现这些数字。
任何人都可以帮助我,或指导我完成这个吗?
多谢你们!
这是我的代码。db.php 用于定义数据库连接`
require_once("db.php"); //include database connection
require_once("constant.php"); //include database connection
require_once ('jpgraph/src/jpgraph.php');
require_once ('jpgraph/src/jpgraph_line.php');
$default=true;
$filter="";
if(isset($_GET["timelapse"])) $timelapse=$_GET["timelapse"];
else $timelapse=TODAY;
$strQueryString="SELECT Date_Time, DissolvedOxygen as DissolvedOxygen FROM datareading";
//echo $strQueryString;
$strQueryString.= " ORDER BY Date_Time ASC";
$query = mysql_query($strQueryString);
$xdata=array();
$ydata=array();
while($row=mysql_fetch_array($query)){
$date = date_create($row["Date_Time"]);
$xdata[]=date_format($date," h:i a");
$ydata[]=$row["DissolvedOxygen"];
}
//print_r($xdata);
$graph = new Graph(920,500); // Initialize Graph
$graph->SetScale("intlin");
$graph->SetMargin(80,30,40,50);
$graph->SetMarginColor('white');
$graph->SetFrame(false,'blue',3);
//Set Title Attributes
$graph->title->Set("Dissolved Oxygen Level");
$graph->yaxis->SetTitleMargin(50);
$graph->title->SetFont(FF_ARIAL,FS_BOLD,12);
//Set Subtitle Attributes
$graph->subtitle->Set("Last 24 Hours");
$graph->subtitle->SetFont(FF_ARIAL,FS_BOLD,10);
$graph->subtitle->SetColor('black');
//$graph->xaxis->SetLabelAngle(90);
$graph->xaxis->SetTickLabels($xdata);
$graph->xaxis->SetTextLabelInterval(2);
// Use Arial font
$graph->xaxis->SetFont(FF_ARIAL,FS_BOLD,9);
$graph->SetAxisLabelBackground(LABELBKG_XAXIS,'orange','red','lightblue','red');
$graph->yaxis->SetFont(FF_ARIAL,FS_BOLD,9);
$graph->xgrid->Show();
// Create the plot line
$p1 = new LinePlot($ydata);
$p1->value->SetFont( FF_FONT1, FS_BOLD);
$p1->value->SetAlign('center');
//Set y-axis title
$graph->yaxis->title->Set("Dissolved Oxygen (mg/L or ppm)");
$graph->yaxis->SetLabelAlign('right','bottom');
$graph->Add($p1);
//print_r($xdata);
$graph->Stroke();`