Function Code for php to draw a bar chart

Source: Internet
Author: User

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 );

}
?>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.