query($sporring); if ($svar->num_rows>0){ $rad=$svar->fetch_assoc(); $nodeid=$rad['id']; echo "

Temperaturer for ".$rad['navn'].", 1 uke

\n"; $nodenavn=$rad['navn']; } if ($nodeid>0) { //Hent siste verdi $dato=date("Y-m-d 00:00:00",strtotime("-7 days")); // I går: date('Y-m-d',strtotime("-1 days")); //Hente data for valgt tid (kommer) $sporring="SELECT tid,temp,fukt,DAY(tid) as dag,HOUR(tid) as time,MINUTE(tid) as minutt FROM maaling WHERE node_id=" . $nodeid ." and tid>'".$dato."' ORDER BY id"; $svar=$dbkobling->query($sporring); $count=0; $mintemp=0.0; $maxtemp=10.0; $dager=0; $dagen=0; $tempdag=0; foreach($svar as $rad){ $rad=$svar->fetch_assoc(); $temp=floatval($rad['temp']); $tempdag=floatval($rad['dag']); if($tempdag!=$dagen) { $dagen=$tempdag; $dager++; } if($temp>$maxtemp) $maxtemp=$temp; if($temp<$mintemp) $mintemp=$temp; // echo "Tid: " .$rad['tid']."Ant: ".$count ." Temp: ".$rad['temp'] ." Fukt:" . $rad['fukt'] ."  "; $tid=floatval($rad['time'])+(floatval($rad['minutt'])/60); if(floatval($rad['fukt'])>0) $data[]=array('',(($dager-1)*24)+$tid,$temp,floatval($rad['fukt'])/10); // echo $count . "," . floatval($rad['temp']) . "," . (floatval($rad['fukt'])/10) . " Tid: ".$tid."
"; $count=$count+1; } } else echo "Feil: " . $sporring . "
" . $dbkobling->error; // echo "Minmax: ".$mintemp. " - " .$maxtemp . "
"; echo "

Siste måling: " . $data[sizeof($data)-1][2] . "

"; $plot = new PHPlot(1300, 600); $plot->SetFailureImage(False); // No error images $plot->SetPrintImage(False); // No automatic output $plot->SetImageBorderType('plain'); $plot->SetPlotType('lines'); $plot->SetDataType('data-data'); $plot->SetDataValues($data); $plot->SetTitle('Temperatur '.$nodenavn); $plot->SetLegend(array('Temperatur', 'Fuktighet/10')); $plot->SetPlotAreaWorld(0, $mintemp-1.0, 24*$dager , $maxtemp); $plot->SetXDataLabelPos('none'); $plot->SetXTickIncrement(4); $plot->SetXLabelType('data'); $plot->SetPrecisionX(0); $plot->SetYTickIncrement(1); $plot->SetYLabelType('data'); $plot->SetPrecisionY(1); $plot->SetDrawXGrid(True); $plot->SetDrawYGrid(True); $plot->DrawGraph(); ?> Plot Image