Har ett 1-wire nätverk där jag loggar temp och elförbrukning och samla data i mysql genom LogTemp.
Håller på med att få till lite grafer för elförbrukningen men får inte in värdena från databasen till grafen.
Så här ser queryn ut:
Kod: Markera allt
$dataArray=array();
$sql="SELECT DATE_FORMAT( DATETIME, '%H:%i' ) AS hour,
(MAX(5B0000000F8AC51D) - MIN(5B0000000F8AC51D)) /1000 AS EL FROM counts
WHERE DATETIME BETWEEN DATE_SUB( NOW() ,
INTERVAL 24 HOUR )
AND NOW( )
GROUP BY HOUR( DATETIME)
ORDER BY hour DESC" or die(mysql_error());
$result = mysql_query($sql) or die('Query failed: ' . mysql_error());
if ($result) {
while ($row = mysql_fetch_assoc($result)) {
$dataArray[$row['hour']]=$row["EL"];
}
}
print_r($dataArray);
Kod: Markera allt
Array ( [23:00] => 2.43 [22:00] => 1.961 [21:00] => 2.074 [20:00] => 2.354 [19:00] => 3.245 [18:00] => 2.766 [17:00] => 2.879 [16:00] => 2.309 [15:00] => 2.268 [14:00] => 2.042 [13:00] => 2.351 [12:00] => 1.951 [11:00] => 1.828 [10:00] => 1.584 [09:40] => 0.642 [08:00] => 1.271 [07:00] => 3.559 [06:00] => 2.93 [05:00] => 3.11 [04:00] => 3.049 [03:00] => 2.878 [02:00] => 2.708 [01:00] => 3.027 [00:00] => 2.719 )
Kod: Markera allt
// Create the graph. These two calls are always required
$graph = new Graph(350,220,'auto');
$graph->SetScale("textlin");
//$theme_class="DefaultTheme";
//$graph->SetTheme(new $theme_class());
$graph->SetBox(false);
//$graph->ygrid->SetColor('gray');
$graph->ygrid->SetFill(false);
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false,false);
// Create the bar plots
$b1plot = new BarPlot($dataArray);
// ...and add it to the graPH
$graph->Add($b1plot);
$b1plot->SetColor("white");
$b1plot->SetFillGradient("#4B0082","white",GRAD_LEFT_REFLECTION);
$b1plot->SetWidth(45);
$graph->title->Set("Bar Gradient(Left reflection)");
// Display the graph
$graph->Stroke();
?>
Nån vänlig själ som ser felet....har hållt på i timmar nu med googlesökningar och provat fram och tillbaka.