Php linear graph function Keywords: PHP/* 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 size of a vertex $ bg: Background color $ line: line color $ text: text color $ dot
Php linear graph function
Keywords: PHP
/*
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 );
}
?>