>4) temperature from DSL_DispStatLog where DSL_StB43 in(1,2,3,4,5,6,7)/* and DSL_Date<'2008-12-16 05:00:00' */order by 1 desc limit 1400)is1 order by 1" ; //$query = "select DSL_Date date, DSL_StHB5&0x0f leds, DSL_StB43 service, (DSL_StB21 & 0x0f)*10+((DSL_StB21 & 0xf0)>>4) temperature from DSL_DispStatLog where DSL_StB43 in(1,2,3,4,5) limit 400"; $result = mysql_query($query); // Determine the nval of records returned $nval = mysql_numrows($result); $maxTemp=0; $minDate="2222-2-22"; $maxDate=0; for ($i=0; $i<$nval-1; $i++){ $tmp=mysql_result($result,$i,"temperature"); $tmp1=mysql_result($result,$i,"date"); if ($tmp>$maxTemp) $maxTemp=$tmp; if ($tmp1>$maxDate) $maxDate=$tmp1; if ($tmp1<$minDate) $minDate=$tmp1; } $diffDate=strtotime($maxDate, 0)-strtotime($minDate, 0); // Add values to the graph // Define .PNG image header("Content-type: image/png"); $imgWidth=10000; $imgHeight=500; $width=$imgWidth; $height=$imgHeight; $vmargin = 20; // top (bottom) vertical margin for title (x-labels) $hmargin = 38; // left horizontal margin for y-labels $base = floor(($width - $hmargin) / $nval); // distance between columns $ysize = $height - 2 * $vmargin; // y-size of plot $xsize = $nval * $base; // x-size of plot // Create image and define colors $image=imagecreate($imgWidth, $imgHeight); $colorWhite=imagecolorallocate($image, 255, 255, 255); $colorNavy = imagecolorallocate($image, 0x00, 0x00, 0x80); $colorGrey=imagecolorallocate($image, 192, 192, 192); $colorBlue=imagecolorallocate($image, 0, 0, 255); $colorBlack=imagecolorallocate($image, 0, 0, 0); // title $titlefont = 3; $title = "DAHECO - time dependency of temperature $minDate - $maxDate ($diffDate)"; // // pixel-width of title // $txtsz = imagefontwidth($titlefont) * strlen($title); $xpos = (int)($hmargin + ($xsize - $txtsz)/2); // center the title $xpos = max(1, $xpos); // force positive coordinates $ypos = 3; // distance from top // plot frame imagerectangle($image, $hmargin, $vmargin, $hmargin + $xsize, $vmargin + $ysize, $colorBlack); imagestring($image, $titlefont, $xpos, $ypos, $title , $colorBlack); // Create border around image //imageline($image, 0, 0, 0, $imgHeight, $colorGrey); //imageline($image, 0, 0, $imgWidth, 0, $colorGrey); //imageline($image, $imgWidth-1, 0, $imgWidth-1, $imgHeight-1, $colorGrey); //imageline($image, 0, $imgHeight-1, $imgWidth-1, $imgHeight-1, $colorGrey); // Create grid //for ($i=1; $i<=$nval; $i++){ //imageline($image, $i*25, 0, $i*25, $imgHeight, $colorGrey); //imageline($image, 0, $i*25, $imgWidth, $i*25, $colorGrey); //} $labelfont = 2; $ngrid = 4; // number of grid lines $dydat = $maxTemp / $ngrid; // data units between grid lines $dypix = $ysize / ($ngrid + 1); // pixels between grid lines for ($i = 0; $i <= ($ngrid + 1); $i++) { $ydat = (int)($i * $dydat); // height of grid line in units of data $ypos = $vmargin + $ysize - (int)($i*$dypix); // height of grid line in pixels $txtsz = imagefontwidth($labelfont) * strlen($ydat); // pixel-width of label $txtht = imagefontheight($labelfont); // pixel-height of label $xpos = (int)(($hmargin - $txtsz) / 2); $xpos = max(1, $xpos); imagestring($image, $labelfont, $xpos, $ypos - (int)($txtht/2), $ydat, $colorBlack); if (!($i == 0) && !($i > $ngrid)) imageline($image, $hmargin - 3, $ypos, $hmargin + $xsize, $ypos, $colorGrey); // don't draw at Y=0 and top } $padding = 2; // half of spacing between columns $yscale = $ysize / (($ngrid+1) * $dydat); // pixels per data unit $xscale = $xsize /$diffDate; // pixels per data unit for ($i = 0; $i<$nval-1; $i++) { $xval = strtotime(mysql_result($result,$i,"date"), 0) -strtotime($minDate, 0) ; $xvalp1 = strtotime(mysql_result($result,$i+1,"date"), 0) -strtotime($minDate, 0) ; $yval = mysql_result($result,$i,"temperature"); $yvalp1 = mysql_result($result,$i+1,"temperature"); // vertical columns $ymax = $vmargin + $ysize; $ymin = $ymax - (int)($yval*$yscale); $yminp1 = $ymax - (int)($yvalp1*$yscale); $xmax = $hmargin +$xvalp1*$xscale ; $xmin = $hmargin + $xval*$xscale ; imageline($image, $xmin, $ymin, $xmax, $ymin, $colorNavy); imageline($image, $xmax, $ymin, $xmax, $yminp1, $colorNavy); //imagefilledrectangle($image, $xmin, $ymin, $xmax, $ymax, $colorNavy); // x labels if($i%15 == 0) { $txtsz = imagefontwidth($labelfont) * strlen($xval); $xpos = $xmin + (int)(($base - $txtsz) / 2); $xpos = max($xmin, $xpos); $ypos = $ymax + 3; // distance from x axis imagestring($image, $labelfont, $xpos, $ypos, strftime("%d %H:%M:%S",$xval+strtotime($minDate, 0)), $colorBlack); } } // Create line graph /*for ($i=0; $i<$nval-1; $i++){ $temperature = mysql_result($result,$i,"temperature"); $temperaturep1 = mysql_result($result,$i+1,"temperature"); imageline($image, $i*25, $vmargin + $ysize - (int)($ysize/$maxTemp*$temperature), ($i+1)*25, $vmargin + $ysize - (int)($ysize/$maxTemp*$temperaturep1), $colorBlue); }*/ // Output graph and clear image from memory imagepng($image); imagedestroy($image); ?>