JpGraph mysql错误。数据库数据未显示在图表上

时间:2014-05-29 14:21:29

标签: php mysql graph web jpgraph

我需要一些帮助来解决我正在处理的Jpgraph脚本的问题。我似乎无法从我的MySQL数据库中获取数据以显示在折线图上。有人可以帮我解决这个问题吗?我已经包含了下面的脚本。

非常感谢

<?php // content="text/plain; charset=utf-8"
require_once ('jpgraph/src/jpgraph.php');
require_once ('jpgraph/src/jpgraph_line.php');

$host = "localhost";
$username = "test";
$password = "fuji12";
$database = "ems";


$connection=mysql_connect ($host, $username, $password);
if (!$connection) {
  die('Not connected : ' . mysql_error());
}

// Set the active mySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
  die ('Can\'t use db : ' . mysql_error());
}

// Select all the rows in the markers table
$sql = "SELECT * FROM DHT22 WHERE MONTH(date) = MONTH(CURDATE()) ORDER BY date LIMIT 31"; 
$result = mysql_query($sql) or die('Query failed: ' . mysql_error());

if ($result) {
while($row = mysql_fetch_array($result)) {
      $date=$row["date"];
      $humd=$row["humdity"];
      $temp=$row["temp"];
      //add to data areray
      $dataArray[$date]=$humd;
      $dataArray2[$date]=$temp;
    }
}

// Setup the graph
$graph = new Graph(550,450);
$graph->SetScale("intlin");

$theme_class=new UniversalTheme;

$graph->SetTheme($theme_class);
$graph->img->SetAntiAliasing(false);
$graph->title->Set('Daily Readings');
$graph->SetBox(false);

$graph->img->SetAntiAliasing();

$graph->yaxis->HideZeroLabel();
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false,false);

$graph->xgrid->Show();
$graph->xgrid->SetLineStyle("solid");
$graph->xgrid->SetColor('#E3E3E3');

// Create the first line
$p1 = new LinePlot($dataArray[$date]);
$graph->Add($p1);
$p1->SetColor("#6495ED");
$p1->SetLegend('Temperature');

// Create the second line
$p2 = new LinePlot($dataArray2[$date]);
$graph->Add($p2);
$p2->SetColor("#B22222");
$p2->SetLegend('Humidity');

$graph->legend->SetFrameWeight(1);

// Output line
$graph->Add($p1);
$graph->Add($p2);
$graph->Stroke();


?>

0 个答案:

没有答案