Php bar chart generation class code // This is a perfect php bar chart generation class code that can generate beautiful and practical column charts
Php tutorial bar chart generation class code
// This is a perfect php bar chart generation class code that can generate beautiful and practical column charts
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 + 40, $ height + 20 );
$ Linecolor = imagecolorallocate ($ im, 12, 12 );
$ Bgcolor = imagecolorallocate ($ im, 235,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 );
}
// Call method:
Header ("content-type: image/png ");
$ Data = array ("yahoo" => 120, "google" => 260, "microsoft" => 320, "ibm" => 290, "sun system" => 150, "inter" => 260 );
Createimage ($ data, 460 );