Php pie chart function

Source: Internet
Author: User
I will introduce myself again. I am a newbie. at that time, I learned php purely to cope with the leadership. let's make a statistical chart. I was originally learning asp, and suddenly it was quite uncomfortable to change the line, however, php is indeed very powerful. Oh, I can't leave him anymore. no, I can handle all the pie charts and column charts, but there are still many questions I don't know. I hope you can give me more advice, I spoke a lot of nonsense about myself.
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)
?>

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.