Next, let's take a look at the function code for php to draw a column chart. Let's take a look at it after a lot of time.
Next, let's take a look at the function code for php to draw a column chart. Let's take a look at it after a lot of time.
Php column chart Function
Keywords: PHP
# For convenience, I made another function to create a column chart.
/* Parameter description:
$ Graphdata: percentage data (Y axis)
$ Label: Title of the X axis
$ Data: actual data (Y axis)
$ Graphwidth: Image Width
$ Graphheight: Image Height
$ Graphscale: height factor ($ graphheight/100)
$ Graphfont: font number
$ Bg; background color value
$ Text: text color value
$ Grid: edge color value
$ Bar: bar color value
$ Bz: Remarks (Chinese is not supported)
*/
Function timage (
$ Graphdata, $ label, $ data,
$ Graphwidth, $ graphheight, $ graphscale, $ graphfont,
$ Bg, $ text, $ grid, $ bar, $ bz)
{
Header ("Content-type: image/gif ");
$ Image = imagecreate ($ graphwidth + 50, $ graphheight + 50 );
$ Bgcolor = imagecolorallocate ($ image, $ bg [0], $ bg [1], $ bg [2]);
$ Textcolor = imagecolorallocate ($ image, $ text [0], $ text [1], $ text [2]);
$ Gridcolor = imagecolorallocate ($ image, $ grid [0], $ grid [1], $ grid [2]);
$ Barcolor = imagecolorallocate ($ image, $ bar [0], $ bar [1], $ bar [2]);
$ Gridabelwidth = imagefontwidth ($ graphfont) * 3 + 1;
$ Gridableheight = imagefontheight ($ graphfont );
Imageline ($ image, $ gridlabelwidth, 0, $ gridlabelwidth, $ graphheight-1, $ gridcolor );
Imageline ($ image, 0, $ graphheight-1, $ graphwidth-1, $ graphheight-1, $ gridcolor );
For ($ I = 0; $ I <$ graphheight; $ I + = $ graphheight/10)
{
Imagedashedline ($ image, 0, $ I, $ graphwidth-1, $ I, $ gridcolor );
Imagestring ($ image, $ graphfont, 0, $ I, round ($ graphheight-$ I)/$ graphscale), $ textcolor );
}
$ Barwidth = ($ graphwidth-$ gridlabelwidth)/count ($ graphdata)-30; # ¿øöö öµ µä×üguí ~è
For ($ I = 0; $ I {
$ Bartopx = $ gridlabelwidth + ($ I + 1) * 20) + ($ I * $ barwidth ); # ¿öö ¿ó ×ózä¾ à À ë
$ Barbottomx = $ bartopx + $ barwidth;
$ Barbottomy = $ graphheight-1;
$ Bartopy = $ barbottomy-($ graphdata [$ I] * $ graphscale );
Imagefilledrectangle ($ image, $ bartopx, $ bartopy, $ barbottomx, $ barbottomy, $ barcolor );
$ Labelx1 = $ bartopx;
$ Labely1 = $ bartopy-15;
$ Labelx2 = $ bartopx;
$ Labely2 = $ graphheight;
Imagestring ($ image, $ graphfont, $ labelx1, $ labely1, "$ graphdata [$ I]". "%", $ textcolor );
Imagestring ($ image, $ graphfont, $ labelx2, $ labely2, "$ label [$ I]", $ textcolor );
Imagestringup ($ image, $ graphfont, $ labelx1 + 10, $ labely1-$ gridableheight, "$ data [$ I]", $ textcolor );
}
Imagestring ($ image, $ graphfont, 1, $ graphheight + 30, $ bz, $ textcolor );
Imagegif ($ image );
}
?>