-
/*php Generate histogram */
- function CreateImage ($data, $twidth, $tspace, $height) {
- $dataName = Array ();
- $dataValue = Array ();
- $i = 0;
- $j = 0;
- $k = 0;
- $num = sizeof ($DATA);
-
foreach ($data as $key = = $val) {
- $dataName [] = $key;
- $dataValue [] = $val;
- }
- $maxnum = max ($data);
- $width = ($twidth + $tspace) * $num + 4;//image ' s width
- $im = imagecreate ($width + +, $height +20);
- $lineColor = Imagecolorallocate ($im, 12,12,12);
- $bgColor = Imagecolorallocate ($im, 255,233,233);
- $tColor = Imagecolorallocate ($im, 123,200,56);
- Imagefill ($im, 0,0, $bgColor);
- Imageline ($im, 0, $height-2, $lineColor);
- Imageline ($im, $height-2, $width + 30-2, $height-2, $lineColor);
- while ($i < $num) {
- Imagefilledrectangle ($im, $i * ($tspace + $twidth) +, $height-$dataValue [$i], $i * ($tspace + $twidth) + + + $twidth, $height -3, $tColor);
- Imagestringup ($im, 4, $i * ($tspace + $twidth) + $twidth/2 +, $height -10, $dataName [$i]. " (". $dataValue [$i].") ", $lineColor);
- $i + +;
- }
- while ($j <= (500/10)) {
- Imagestringup ($im, 4, 2, $height-$j * + ten, $j *, $lineColor);
- $j = $j + 10;
- }
- while ($k <= (500/10)) {
- if ($k! = 0)
- Imageline ($im, $height-$k *, $height-$k *, $lineColor);
- $k = $k + 10;
- }
- Imagepng ($im);
- }
-
Histogram Call method
- Header ("Content-type:image/png");
- $data = Array ("Yahoo" + +), "Google", "Microsoft" + +, "IBM" +, "Sun System", "Inter" =& Gt 20);
- Change the data in this line to yours: $data = Array ("Yahoo" + +, "Google" = 260, "Microsoft" + +), "IBM" + +, "Sun System" "Inter" (220);
- CreateImage ($data, 50,25,500);
- ?>
Copy Code
Bar chart, as follows:
|