我正在连接到 mySQL 并运行一个简单的查询并将查询返回到一个数组中,然后将数组内爆并尝试使用 jpgraph 对其进行绘图,但我没有得到任何数据点。
<?php
// content="text/plain; charset=utf-8"
include($_SERVER["DOCUMENT_ROOT"] . "/jpgraph/jpgraph.php");
include($_SERVER["DOCUMENT_ROOT"] . "/jpgraph/jpgraph_line.php");
$monday1 = strtotime("this monday");
$monday2 = date("Y-m-d",$monday1);
//connect to Database and return graph values
$con=mysql_connect("localhost:3306","root","","mysql");
$db_selected = mysql_select_db('mysql', $con);
if (!$db_selected)
{
die ('Can\'t use mysql : ' . mysql_error());
}
$mondayquery = "SELECT invoicetotal
FROM thermdata
WHERE CAST( datestamp AS DATE ) = '$monday2'
ORDER BY datehour";
$mondayresult = mysql_query($mondayquery,$con);
while($mondayinfo = mysql_fetch_array( $mondayresult ))
{
$monimp[] = $mondayinfo['invoicetotal'];
}
// Convert the array
$mondayfinal = implode(",", $monimp);
//set variables for graph values as array
$datay1 = array($mondayfinal);
// Setup the graph
$graph = new Graph(1200,600);
$graph->SetScale("intint");
$theme_class=new UniversalTheme;
$graph->SetTheme($theme_class);
$graph->img->SetAntiAliasing(false);
$graph->SetMargin(10,10,-500,10);
$graph->SetBox(false);
$graph->legend->SetPos(.01,0,'left','top');
$graph->legend->SetColumns(7);
$graph->legend->SetFont(FF_FONT2,FS_NORMAL, 72);
$graph->legend->SetHColMargin(10);
$graph->legend->SetLineWeight(5);
$graph->img->SetAntiAliasing();
$graph->yaxis->HideZeroLabel();
$graph->yaxis->HideLine(true);
$graph->yaxis->HideTicks(true,true);
$graph->yaxis->SetColor('white','white');
$graph->xgrid->Show();
$graph->xgrid->SetLineStyle("solid");
$graph->xaxis->SetTickLabels(array('00','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24'));
$graph->xgrid->SetColor('#E3E3E3');
// Create the first line
$p1 = new LinePlot($datay1);
$graph->Add($p1);
$p1->SetColor("#ff0000");
$p1->SetLegend('Sunday');
// Output line
$graph->Stroke();
mysql_close($con);
?>
基本上,数据库每小时都包含一个新的 invoicetotal,我想在本周每天 24 小时内绘制它们。
变量 $mondayfinal 解析为“0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,278,627,1235,1919 ,2015”,但我看不出我做错了什么阻止 jpgraph 绘制它们。
任何帮助将不胜感激!