Nu är problemet att få fram grafer.
Får fram grafen för ett dygn men klockslagen stämmer inte. Allt loggas i en mysqldatabas med 5 minuters mellanrum.
koden enligt följande ger denna graf.
http://www.sadelmakaren.nu/~jonasweb/jp_graph.phpKoden där säkert några känner igen sig på något ställe.
Någon som kan ge tips ?
<?php
include ("/usr/share/jpgraph/jpgraph.php");
include ("/usr/share/jpgraph/jpgraph_line.php");
mysql_connect("localhost", "anvid", "lösen") or die("Kan ej ansluta: " . mysql_error());
mysql_select_db("digitemp") or die("Kan ej öppna databas digitemp");
if (isset($_GET['From'])) {
$fran = $_GET['From'];
$till = $_GET['To'];
} elseif (isset($_GET['Day'])) {
$fran = Date("Y-m-d H:i",strtotime($_GET['Day']));
$till = Date("Y-m-d H:i",strtotime($fran) +(1 * 24 * 60 * 60));
}
else {
$till = Date("Y-m-d H:i", time());
$fran = Date("Y-m-d H:i",strtotime($till) - (1 * 24 * 60 * 60));
}
$query = "SELECT `kbin`, `kbut`, `gvuf`, `gvur`, `rf`, `rr`, `vv`, `ute` FROM digitemp WHERE time >= '$fran' and time < '$till'";
$result = mysql_query($query) or die("SQL fråga felaktig: " . mysql_error());
for ($i=strtotime($fran); $myrow=mysql_fetch_row($result); $i = $i + 60) {
$ydataa[] = $myrow[5];
$ydatab[] = $myrow[4];
$ydatac[] = $myrow[3];
$ydatad[] = $myrow[2];
$ydatae[] = $myrow[1];
$ydataf[] = $myrow[0];
$ydatag[] = $myrow[6];
$ydatah[] = $myrow[7];
$xdata[] = Date("H:i", $i);
}
// Create the graph. These two calls are always required
$graph = new Graph(1024,600,"auto");
$graph->SetScale("textlin",-20,55);
$graph->title->Set("Värmepumpdata: ".Date("Y-m-d H:i",strtotime($fran))." -> ".Date("Y-m-d H:i",strtotime($till)));
$graph ->img->SetMargin(40,20,30,70);
$graph ->xaxis->SetTextTickInterval(60);
$graph ->xaxis->SetTextLabelInterval(1);
$graph ->xaxis->SetTickLabels($xdata);
$graph->yaxis->SetColor("red");
$graph->yaxis->SetWeight(2);
$graph ->xaxis->SetFont(FF_FONT1,FS_BOLD);
$graph ->yaxis->title->Set("Grader");
$graph ->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph ->SetShadow();
$graph ->legend->SetLayout(LEGEND_HOR);
$graph ->legend->Pos(.5,.94,"center","center");
$graph ->ygrid->Show(true,true);
$graph->xgrid->Show(true,false);
// Create the linear plot
$lineplot2=new LinePlot($ydataa);
$lineplot2->SetColor("blue");
$lineplot2 ->SetLegend("Radiator-retur");
$lineplot2->SetWeight(2);
// Create the linear plot
$lineplot1=new LinePlot($ydatab);
$lineplot1->SetColor("violetred4");
$lineplot1 ->SetLegend("Radiator-fram");
$lineplot1->SetWeight(2);
// Create the linear plot
$lineplot3=new LinePlot($ydatac);
$lineplot3->SetColor("springgreen");
$lineplot3 ->SetLegend("Golvvärmeuppe-retur");
$lineplot3->SetWeight(2);
// Create the linear plot
$lineplot4=new LinePlot($ydatad);
$lineplot4->SetColor("red");
$lineplot4 ->SetLegend("Golvvärmeuppe-fram");
$lineplot4->SetWeight(2);
// Create the linear plot
$lineplot5=new LinePlot($ydatae);
$lineplot5->SetColor("black");
$lineplot5 ->SetLegend("KB-in");
$lineplot5->SetWeight(2);
// Create the linear plot
$lineplot6=new LinePlot($ydataf);
$lineplot6->SetColor("yellow3");
$lineplot6 ->SetLegend("KB-ut");
$lineplot6->SetWeight(2);
// Create the linear plot
$lineplot7=new LinePlot($ydatag);
$lineplot7->SetColor("violetred1");
$lineplot7 ->SetLegend("Varmvatten");
$lineplot7->SetWeight(2);
// Create the linear plot
$lineplot8=new LinePlot($ydatah);
$lineplot8->SetColor("turquoise2");
$lineplot8 ->SetLegend("Ute");
$lineplot8->SetWeight(2);
// Add the plot to the graph
$graph->Add($lineplot1);
$graph->Add($lineplot2);
$graph->Add($lineplot4);
$graph->Add($lineplot3);
$graph->Add($lineplot5);
$graph->Add($lineplot6);
$graph->Add($lineplot7);
$graph->Add($lineplot8);
// Display the graph
$graph->Stroke();
?>