0) { imageline($handle,10,$ydim-$cur+3,$xdim,$ydim-$cur+3,$lines); imagestring($handle,1,0,$ydim-$cur,$val,$text); $cur -= $y_delta; $val -= $bar_delta; } $padleft = 15; $padding = 5; $available = $xdim-$padleft-count($data)*$padding; $width = $available/count($data); $cLeft = $padleft; foreach($data as $key=>$value) { imagefilledrectangle($handle,$cLeft,$ydim-$ydim*$value/$max+3,$cLeft+$width,$ydim,$bars); $strwidth = strlen($key)*6; $offset = ($width-$strwidth)/2; imagestring($handle,3,$cLeft+$offset,$ydim-15,$key,$text); $cLeft += $width+$padding; } header("Content-Type: image/png"); imagepng($handle); imagedestroy($handle); } function line_graph($data,$xdim,$ydim,$m_m_0=false,$round_to = 1, $MIN = null, $MAX = null, $deltas = null) { $DELTA_COUNT = 5; $handle = imagecreate($xdim,$ydim); $background = imagecolorallocate($handle, 255,255,255); $text = imagecolorallocate($handle, 0,0,0); $datcolors = array(imagecolorallocate($handle,255,0,0), imagecolorallocate($handle,0,255,0), imagecolorallocate($handle, 0,0,255), imagecolorallocate($handle,255,255,0), imagecolorallocate($handle,0,255,255), imagecolorallocate($handle,255,0,255)); $min = min($data[0]); $max = max($data[0]); foreach($data as $next) { $t = min($next); $min = $min < $t ? $min : $t; $t = max($next); $max = $max > $t ? $max : $t; } if ($MIN === null) $MIN = $min; if ($MAX === null) $MAX = $max; $range = $MAX-$MIN; if (!$deltas) { if ($round_to) { if ($MAX%$round_to) $MAX = ceil($MAX/$round_to)*$round_to; if ($MIN%$round_to) $MIN = floor($MIN/$round_to)*$round_to; } $range = $MAX-$MIN; $deltas = $range/$DELTA_COUNT; $deltas = $deltas ? $deltas : 1; } $c = 0; $bar_y_delta = floor($ydim/$range)*$scaled; if ($m_m_0) { imagestring($handle,1,0,$ydim-10,round($MIN,3),$text); imagestring($handle,1,0,0,round($MAX,3),$text); } else while ($MIN+$c*$deltas <= $MAX) { imageline($handle,10,$ydim-$bar_y_delta*$c,$xdim,$ydim-$bar_y_delta*$c,$text); imagestring($handle,1,0,$ydim-$bar_y_delta*$c,$MIN+($c++)*$deltas,$text); } $transform = $ydim/$range; for ($i = 0 ; $i < count($data) ; $i++) { $xoffset = ($xdim-10)/(count($data[$i])-1); for ($j = 0 ; $j < count($data[$i])-1 ; $j++) { imageline($handle, $xoffset*$j+10, $ydim-($data[$i][$j]-$MIN)*$transform, $xoffset*($j+1)+10, $ydim-($data[$i][$j+1]-$MIN)*$transform, $datcolors[$i] ); if ($data[$i][$j] != $MIN) imagefilledellipse($handle,$xoffset*$j+10,$ydim-($data[$i][$j]-$MIN)*$transform,5,5,$datcolors[$i]); } if ($data[$i][$j] != $MIN) imagefilledellipse($handle,$xoffset*$j+10,$ydim-($data[$i][$j]-$MIN)*$transform,5,5,$datcolors[$i]); } header("Content-Type: image/png"); imagepng($handle); imagedestroy($handle); } ?>