Also have the question friend can add me qq:460634320, everybody discuss together.
:
Copy the Code code as follows:
function CreateImage ($data, $twidth, $tspace, $height) {
Header ("Content-type:image/jpeg");
$dataname = Array ();
$datavalue = Array (); The value inside the//data
$i = 0;
$j = 0;
$k = 0;
$num = sizeof ($DATA);
foreach ($data as $key = = $val) {
$dataname [] = $key;
$datavalue [] = $val;
}
$width = $num * ($twidth + $tspace) + 20;//Get the width of the image
$im = Imagecreate ($width, $height);//Create Image
$bgcolor = Imagecolorallocate ($im, 255,255,255);//Background color
$jcolor = Imagecolorallocate ($im, 255,255,0);//Background color of Rectangle
$acolor = Imagecolorallocate ($im, 0,0,0);//Line Color
Imageline ($im, $height -20, $width -5, $height -20, $acolor);//x axis
Imageline ($im, $height -20,25,2, $acolor);//y Shaft
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 a value on a pillar
Imagestring ($im, 3, $i * ($tspace + $twidth) +40+ $twidth/2, $height -15, $dataname [$i], $acolor);//write a value under a pillar
$i + +;
}
while ($j < 400/10) {
Imageline ($im, $height -20)-$j *8,28, ($height -20)-$j *8, $acolor);//Draw a scale
Imagestring ($im, 2,5, ($height -30)-$j *8, $j *10, $acolor);//Mark scale value
$j = $j +10;
}
Imagejpeg ($im);
}
$data =array ("1" =>25, "2" =>30, "3" =>21);
CreateImage ($data, 40,40,300);
?>
The above describes the histogram PHP histogram implementation code, including the bar chart aspect of the content, I hope that the PHP tutorial interested in a friend helpful.