-
-
/** - * php histogram imagefilledrectugle function use case
- * by bbs.it-home.org
- */
- function createImage($data,$twidth,$tspace,$height){
- header("Content-Type:image/ jpeg");
- $dataname = array();
- $datavalue = array();//The value in data
- $i = 0;
- $j = 0;
- $k = 0;
- $num = sizeof( $data);
foreach($data as $key => $val){
- $dataname[] = $key;
- $datavalue[] = $val;
- }< /p>
$width = $num * ($twidth + $tspace) + 20 ;//Get the width of the image
- $im = imagecreate($width,$height);//Create image p>
$bgcolor = imagecolorallocate($im,255,255,255);//Background color
- $jcolor = imagecolorallocate($im,255,255,0);//Background color of the rectangle
- $acolor = imagecolorallocate($im ,0,0,0);//The color of the line
imageline($im,25,$height-20,$width-5,$height -20,$acolor);/ /X-axis
- imageline($im,25,$height-20,25,2,$acolor);//Y-axis
- while($i< $num){
- imagefilledrectangle($im,$i*($tspace+ $twidth)+40,$height-$datavalue[$i]-20,$i*($twidth+$tspace)+$tspace+40,$height-20,$jcolor);//Draw a rectangle
- imagestring($ im,3,$i*($tspace+$twidth)+40+$twidth/2,$height-$datavalue[$i]-35,$datavalue[$i],$acolor);//Write on the pillar Output value
- imagestring($im,3,$i*($tspace+$twidth)+40+$twidth/2,$height-15,$dataname[$i],$acolor);//Write it below the column Value
- $i ++;
}
- while($j < 400/10){
- imageline($im,25,($height-20)-$j*8, 28,($height-20)-$j*8,$acolor);//Draw the scale
- imagestring($im,2,5,($height-30)-$j*8,$j*10, $acolor);//Mark the scale value
- $j = $j +10;
- }
- imagejpeg($im);
- }
- $data =array("1"=>25,"2"=> 30,"3" =>21 );
- createImage($data,40,40,300);
- ?>
-
Copy code
|