How to use php for linear graph functions

Source: Internet
Author: User
How to use php for linear graph functions is so excited for php (as the mainstream development language!
The following describes the linear graph functions of php (as the mainstream development language:

/*
Function description
$ Data: Y axis data (array)
$ Graphdata: Y axis data-percentage (array)
$ Label: x-axis data (array)
$ Height: Image height
$ Width: Image width
$ Font: font size
$ Dot: determines the vertex size.
$ Bg: Background color
$ Line: line color
$ Text: text color
$ Dotcolor: spot color
$ File: output image file name
*/

Function qximage ($ data,
$ Graphdata,
$ Label,
$ Height,
$ Width,
$ Font,
$ Dot,
$ Bg,
$ Line,
$ Text,
$ Dotcolor,
$ File)
{
$ Jc = $ height/100;
$ Fontwidth = imagefontwidth ($ font );
$ Fontheight = imagefontheight ($ font );

$ Image = imagecreate ($ width, $ height + 20 );
$ Bg = imagecolorallocate ($ image, $ bg [0], $ bg [1], $ bg [2]);
$ Line = imagecolorallocate ($ image, $ line [0], $ line [1], $ line [2]);
$ Text = imagecolorallocate ($ image, $ text [0], $ text [1], $ text [2]);
$ Dotcolor = imagecolorallocate ($ image, $ dotcolor [0], $ dotcolor [1], $ dotcolor [2]);
Imageline ($ image, 0, 0, $ height, $ line );
Imageline ($ image, 0, $ height, $ width, $ height, $ line );
For ($ I = 1; $ I <11; $ I ++)
{
Imagedashedline ($ image, 0, $ height-$ jc * $ I * 10, $ width, $ height-$ jc * $ I * 10, $ line );
Imagestring ($ image, $ font, 0, $ height-$ jc * $ I * 10, $ I * 10, $ text );
}
For ($ I = 0; $ I {
# Echo $ tmp ."
";
$ X1 = ($ width-50)/count ($ data) * ($ I) + 40;
# Echo $ x1 ."
";
$ Y1 = $ height-$ graphdata [$ I] * $ jc;
$ X2 = $ x1;
$ Y2 = $ y1 + $ graphdata [$ I] * $ jc;
# Echo $ y1 ."
";
Imagestring ($ image, $ font, $ x1, $ y1-2 * $ fontheight, $ graphdata [$ I]. "% (". $ data [$ I]. ")", $ text );
Imagearc ($ image, $ x1, $ y1, $ dot, $ dot, 0,360, $ dotcolor );
Imagefilltoborder ($ image, $ x1, $ y1, $ dotcolor, $ dotcolor );
Imagestring ($ image, $ font, $ x1, $ y2, $ label [$ I], $ text );
If ($ I> 0)
{
Imageline ($ image, $ tmpx1, $ tmpy1, $ x1, $ y1, $ line );
}
$ Tmpx1 = $ x1; $ tmpy1 = $ y1;
}
Imagegif ($ image, $ file );
}
?>

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.