Php generates a 3D pie chart

Source: Internet
Author: User

Php generates a 3D pie chart

<? Php
/*
* Created on 2009-5-26
* Author: deepblue
*/

$ Image = imagecreatetruecolor (200,200); // create a canvas named 200*200;

// Create multiple and differentiated colors
$ Red = imagecolorallocate ($ image, 255, 0, 0 );
$ Blue = imagecolorallocate ($ image, 255 );
$ Yellow = imagecolorallocate ($ image, 255,255, 0 );
$ Violet = imagecolorallocate ($ image, 255 );
$ White = imagcolorallocate ($ image, 255,255,255 );
$ Black = imagecolorallocate ($ image, 0, 0 );


// Use the for loop to create the underlying 3D effect
For ($ I = 120; $ I> 100; $ I --){
Imagefilledarc ($ image, 100, $ I, 200,120, $ red, IMG_ARC_PIE); // The IMG_ARC_PIE annotations are as follows:

Imagefilledarc ($ image, 100, $ I, 200,120, $ blue, IMG_ARC_PIE );
Imagefilledarc ($ image, 100, $ I, 200,120, 80,360, $ yellow, IMG_ARC_PIE );
}
// Bool imagefilledarc (resource image, int cx, int cy, int w, int h, int s, int e, int color, int style)
//
// Imagefilledarc () draws an elliptical arc in the image with cx and cy (0 in the upper left corner of the image. If the call succeeds, TRUE is returned. If the call fails, FALSE is returned. W and h respectively specify the width and height of the elliptic, and s and e Parameters specify the start and end points with an angle. Style can be the values of the following values after bitwise OR (OR:
//
// IMG_ARC_PIE
//
// IMG_ARC_CHORD
//
// IMG_ARC_NOFILL
//
// IMG_ARC_EDGED


// This layer is the effect of the top layer, so that the three-dimensional effect will come out!
Imagearc ($ image, 100,100,200,120, 0,360, $ black); // Add a black edge ring to make the 3D effect more visible.
Imagefilledarc ($ image, 100,100,200,120, $ red, IMG_ARC_PIE );
Imagefilledarc ($ image, 100,100,200,120, $ blue, IMG_ARC_PIE );
Imagefilledarc ($ image, 100,100,200,120, 80,360, $ yellow, IMG_ARC_PIE );

// Add percentage data. If necessary, you can perform batch operations to input the input data to the image.
$ Str = iconv ("gbk", "UTF-8", "36%"); // This conversion is required if you want to enter Chinese characters. Example: occupied: 30%;
Imagettftext ($ image, 10,360-15,100 + 70,115, $ white, "simhei. ttf", $ str );

Imagejpeg ($ image );
Imagedestroy ($ image );

?>

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.