Php dynamic generation of pie chart code

Source: Internet
Author: User
Tags 0xc0

*/
// Create an image
$ Image = imagecreatetruecolor (300,300 );
// Define the color required to draw a pie chart
$ White = imagecolorallocate ($ image, 0xff, 0xff, 0xff );
$ Gray = imagecolorallocate ($ image, 0xc0, 0xc0, 0xc0 );
$ Darkgray = imagecolorallocate ($ image, 0x90, 0x90, 0x90 );
$ Navy = imagecolorallocate ($ image, 0x00, 0x00, 0x80 );
$ Darknavy = imagecolorallocate ($ image, 0x00, 0x00, 0x50 );
$ Red = imagecolorallocate ($ image, 0xff, 0x00, 0x00 );
$ Darkred = imagecolorallocate ($ image, 0x90, 0x00, 0x00 );

/*
Imagecolorallocate -- assign color to an image description int imagecolorallocate (resource image, int red, int green, int blue) imagecolorallocate () returns an identifier, represents a color composed of a given rgb component. The image parameter is the return value of the imagecreate () function. Red, green, and blue are the required colors respectively. These parameters are integers from 0 to 255 or hexadecimal values 0x00 to 0xff. Imagecolorallocate () must be called to create the color of each image used in the image.
*/
// Draw
For ($ I = 160; $ I> 150; $ I --)
{
Imagefilledarc ($ image, 150, $ I, 200, 80, 0, 45, $ darknavy, img_arc_pie );
Imagefilledarc ($ image, 150, $ I, 200, 80, 45, 75, $ darkgray, img_arc_pie );
Imagefilledarc ($ image, 150, $ I, 200, 80, 75,360, $ darkred, img_arc_pie );
}
Imagefilledarc ($ image, 150,150,200, 80, 0, 45, $ navy, img_arc_pie );
Imagefilledarc ($ image, 150,150,200, 80, 45, 75, $ gray, img_arc_pie );
Imagefilledarc ($ image, 150,150,200, 80, 75,360, $ red, img_arc_pie );
Header ('content-type: image/png ');
Imagepng ($ image );
Imagedestroy ($ image );
/*
The imagefilledarc () function fills an elliptical arc with a specified color. With this function, you can easily draw a pie chart for statistics. The following describes how to use the imagefilledarc () function.

The execution result of the code is shown in figure 22.8:
*/

// Draw lines in the image

// Create a true color image
$ Img = imagecreatetruecolor (0, 300,300 );
$ White = imagecolorallocate ($ img, 255,255,255 );
$ Red = imagecolorallocate ($ img, 255, 0, 0 );
$ Green = imagecolorallocate ($ img, 0,255, 0 );
// Draw an ellipse on the image
Imagefilledellips tutorial e ($ img, 150,150,250,100, $ red );
Imagefilledellipse ($ img, 150,150,100,250, $ green );
// Output image
Header ("content-type: image/png ");
Imagepng ($ img );
// Destroy the image
Imagedestroy ($ img );
/*
The execution result of the code is shown in figure 22.9:
*/

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.