php dynamically generated pie chart code

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags code create function image network network programming php php tutorial

* /
// Create the image
$ image = imagecreatetruecolor (300,300);
// Define the color needed to draw the 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 a color to an image Description imagecolorallocate () Returns an identifier representing the color of the given rgb component. The image parameter is the return value of the imagecreate () function. red, green and blue are the red, green and blue components of the desired color, respectively. These parameters are integers from 0 to 255 or 0x00 to 0xff in hexadecimal. imagecolorallocate () must be called to create each color used in the image represented by image.
* /
// drawing
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 allows you to fill an elliptical arc with the specified color at the same time. With this function of this function, it is easy to draw a pie chart for statistics. Here's how to use the imagefilledarc () function

The code execution results shown in Figure 22.8:
* /

// draw lines in the picture

// Create a true color image
$ img = imagecreatetruecolor (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 code execution results shown in Figure 22.9:
* /

Related Article

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.