Introduction: This is a detailed page of PHP pie chart functions. It introduces PHP, related knowledge, skills, experience, and some PHP source code.
Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 330117 'rolling = 'no'>
Let me introduce myself again.
I was a newbie. At that time, I learned PHP purely to cope with the leadership. Let's make a Statistical Chart. I originally learned ASP and suddenly changed the line. However, PHP is really powerful, well, I can't leave him anymore. No, I have fixed all the pie charts and column charts, but I still have a lot of questions. I hope you can give me more advice and talk a lot of nonsense, I thought it was writing a letter.
My contact information is:
Email: qingdaohb@yeah.net
Http://qdlover.yeah.net
The boss rushed and couldn't help it. The pie chart function was released. You can grab it soon.
########
Bimage. php3
########
/*
Function Description
$ Chartdata: data, which is an array element
$ Chartfont: font size
$ Chartdiameter: determines the size of the pie (It depends on whether you are hungry, huh, huh)
$ Chartlabel: title, also an array element
$ Colorslice: color array, for example, $ TMP = array255, 255,255); $ colorslic = array ($ TMP );
$ Colorborder: border color, array
$ Colortext: text color, array
$ Colorbody: background color, array
$ File: output image file name */
Function bimage ($ chartdata,
$ Chartfont,
$ Chartdiameter,
$ Chartlabel,
$ Colorslice,
$ Colorbody,
$ Colorborder,
$ Colortext,
$ File
)
{
$ Chartdiameter = 150;
$ chartfontheight = imagefontheight ($ chartfont);
$ d1 = 10; $ D2 = 20; $ D3 = 30; $ D4 = 40; $ D5 = 50;
$ chartdata = array ($ D1, $ D2, $ D3, $ D4, $ D5);
$ chartlabel = array ("d1", "D2 ", "D3", "D4", "D5");
$ chartwidth = $ chartdiameter 20;
$ chartheight = $ chartdiameter 20 ($ chartfontheight 2) * count ($ chartdata);
header ("Content-Type: image/GIF");
$ image = imagecreate ($ chartwidth, $ chartheight );
$ colorbody = imagecolorallocate ($ image, $ colorbody [0], $ colorbody [1], $ colorbody [2]);
$ colortext = imagecolorallocate ($ image, $ colortext [0], $ colortext [1], $ colortext [2]);
$ colorborder = imagecolorallocate ($ image, $ colorborder [0], $ colorborder [1], $ colorborder [2]);
for ($ I = 0; $ I
{
$ T = imagecolorallocate ($ image, $ colorslice [$ I] [0], $ colorslice [$ I] [1], $ colorslice [$ I] [2]);
$ colorslice [$ I] = $ t;
}
For ($ I = 0; $ I
{
$ Charttotal = $ chartdata [$ I];
}
$ Chartcenterx = $ chartdiameter/2 10;
$ Chartcentery = $ chartdiameter/2 10;
$ Degrees = 0;
For ($ I = 0; $ I
{
$ Startdegrees = round ($ degrees );
$ Degrees = ($ chartdata [$ I]/$ charttotal) * 360 );
$ Enddegrees = round ($ degrees );
$ Currentcolor = $ colorslice [$ I % (count ($ colorslice)];
Imagearc ($ image,
$ Chartcenterx,
$ Chartcentery,
$ Chartdiameter,
$ Chartdiameter,
$ Startdegrees,
$ Enddegrees,
$ Currentcolor );
List ($ arcx, $ Arcy) = circle_point ($ startdegrees, $ chartdiameter );
Imageline ($ image,
$ Chartcenterx,
$ Chartcentery,
Floor ($ chartcenterx $ arcx ),
Floor ($ chartcentery $ Arcy ),
$ Currentcolor );
List ($ arcx, $ Arcy) = circle_point ($ enddegrees, $ chartdiameter );
Imageline ($ image,
$ Chartcenterx,
$ Chartcentery,
Ceil ($ chartcenterx $ arcx ),
Ceil ($ chartcentery $ Arcy ),
$ Currentcolor );
$ Midpoint = round ($ enddegrees-$ startdegrees)/2) $ startdegrees );
List ($ arcx, $ Arcy) = circle_point ($ midpoint, $ chartdiameter/2 );
Imagefilltoborder ($ image,
Floor ($ chartcenterx $ arcx ),
Floor ($ chartcentery $ Arcy ),
$ Currentcolor,
$ Currentcolor );
}
Imagearc ($ image,
$ Chartcenterx,
$ Chartcentery,
$ Chartdiameter,
$ Chartdiameter,
0,360,
$ Colorborder );
Imagefilltoborder ($ image,
Floor ($ chartcenterx ($ chartdiameter/2) 2 ),
$ Chartcentery,
$ Colorborder,
$ Colorborder );
For ($ I = 0; $ I
{
$ Currentcolor = $ colorslice [$ I % (count ($ colorslice)];
$ Liney = $ chartdiameter 20 ($ I * ($ chartfontheight 2 ));
Imagerectangle ($ image,
10,
$ Liney,
20 $ chartfontheight,
$ Liney $ chartfontheight,
$ Colorbody );
Imagefilltoborder ($ image,
12,
$ Liney 2,
$ Colorbody,
$ Currentcolor );
Imagestring ($ image,
$ Chartfont,
40 $ chartfontheight,
$ Liney,
"$ Chartlabel [$ I]: $ chartdata [$ I]",
$ Colortext );
}
Imagegif ($ image, $ file );
}
Function radians ($ degrees)
{
Return ($ degrees * (PI ()/180.0 ));
}
Function circle_point ($ degrees, $ diameter)
{
$ X = cos (radians ($ degrees) * ($ diameter/2 );
$ Y = sin (radians ($ degrees) * ($ diameter/2 );
Return (Array ($ X, $ y ));
}
?>
###########
This is an example of a call.
###########
Include ("bfunc. php3 ");
$ Chartdiameter = 250;
$ Chartfont = 5;
$ D1 = 10; $ D2 = 20; $ D3 = 30; $ D4 = 40; $ D5 = 50;
$ Chartdata = array ($ D1, $ D2, $ D3, $ D4, $ D5 );
$ Chartlabel = array ("d1", "D2", "D3", "D4", "D5 ");
$ Colorbody = array (0xff, 0xff, 0xff );
$ Colorborder = array (0x00,0x00,0x00 );
$ Colortext = array (0xff, 0xff, 0xff );
$ Color1 = array (0xff, 0x00,0x00 );
$ Color2 = array (0x00, 0xff, 0x00 );
$ Color3 = array (0x00,0x00, 0xff );
$ Color4 = array (0xff, 0xff, 0x00 );
$ Color5 = array (0xff, 0x00, 0xff );
$ Colorslice = array ($ color1, $ color2, $ color3, $ color4, $ color5 );
$ File = "tj.gif"
Bimage ($ chartdata,
$ Chartfont,
$ Chartdiameter,
$ Chartlabel,
$ Colorslice,
$ Colorbody,
$ Colorborder,
$ Colortext,
$ File)
?>
More articles on "php pie chart functions"
Love J2EE follow Java Michael Jackson video station JSON online tools
Http://biancheng.dnbcw.info/php/330117.html pageno: 11.