<?
/* BkJia essence: generate a bar chart in PHP */
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; // images width
$ Im = imagecreate ($ width + 40, $ height + 20 );
$ LineColor = imagecolorallocate ($ im, 12, 12 );
$ BgColor = imagecolorallocate ($ im, 255,233,233 );
$ TColor = imagecolorallocate ($ im, 123,200, 56 );
Imagefill ($ im, 0, 0, $ bgColor );
Imageline ($ im, 30, 0, 30, $ height-2, $ lineColor );
Imageline ($ im, 30, $ height-2, $ width + 30-2, $ height-2, $ lineColor );
While ($ I <$ num ){
Imagefilledrectangle ($ im, $ I * ($ tspace + $ twidth) + 40, $ height-$ dataValue [$ I], $ I * ($ tspace + $ twidth) + 40 + $ twidth, $ height-3, $ tColor );
Imagestringup ($ im, 4, $ I * ($ tspace + $ twidth) + $ twidth/2 + 30, $ height-10, $ dataName [$ I]. "(". $ dataValue [$ I]. ")", $ lineColor );
$ I ++;
}
While ($ j <= (500/10 )){
Imagestringup ($ im, 4, 2, $ height-$ j * 10 + 10, $ j * 10, $ lineColor );
$ J = $ j + 10;
}
While ($ k <= (500/10 )){
If ($ k! = 0)
Imageline ($ im, 28, $ height-$ k * 10, 32, $ height-$ k * 10, $ lineColor );
$ K = $ k + 10;
}
Imagepng ($ im );
}
Header ("content-type: image/png ");
$ Data = array ("Yahoo" => 100, "Google" => 260, "Microsoft" => 320, "IBM" => 250, "Sun System" => 150, "Inter" => 220 );
CreateImage ($ data, 500 );
?>
Change the data in this line to yours: $ data = array ("Yahoo" => 100, "Google" => 260, "Microsoft" => 320, "IBM" => 250, "Sun System" => 150, "Inter" => 220 );