drduh44480 2014-05-29 14:21
浏览 67

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

I require some help in resolving a problem with a Jpgraph script I'm working on. I can't seem to get the data from my MySQL database to show on the line graph. Can anyone help me in resolving this problem please? I have included the script below.

Many Thanks

<?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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了