PHP generates 3D pie Shape Data Statistics Chart

Source: Internet
Author: User

<?php
/*
* Created on 2009-5-26
*author:deepblue
*/

$image = Imagecreatetruecolor (200,200); Create a 200*200 canvas;

Create multiple, differentiated colors
$red = Imagecolorallocate ($image, 255,0,0);
$blue = Imagecolorallocate ($image, 0,0,255);
$yellow = Imagecolorallocate ($image, 255,255,0);
$violet = Imagecolorallocate ($image, 255,0,255);
$white = Imagecolorallocate ($image, 255,255,255);
$black = Imagecolorallocate ($image, 0,0,0);


Create a 3D effect bottom effect with a for loop
For ($i =120 $i >100; $i-) {
Imagefilledarc ($image, MB, $i, 200,120,0,30, $red, img_arc_pie);//img_arc_pie notes are as follows:

Imagefilledarc ($image, MB, $i, 200,120,30,80, $blue, Img_arc_pie);
Imagefilledarc ($image, MB, $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 represented by Cx,cy (0, 0 in the upper-left corner of the image). Returns TRUE if successful, and returns FALSE if it fails. W and H Specify the width and height of the ellipse respectively, and the S and e parameters specify the starting and ending points at the angle. The style can be a value that is bitwise OR (or) of the following values:
//
Img_arc_pie
//
Img_arc_chord
//
Img_arc_nofill
//
Img_arc_edged


This layer is the top layer of the effect, so that the stereo effect came out!
Imagearc ($image, 100,100,200,120,0,360, $black);//Add a black rim so that the 3D effect looks more obvious.
Imagefilledarc ($image, 100,100,200,120,0,30, $red, Img_arc_pie);
Imagefilledarc ($image, 100,100,200,120,30,80, $blue, Img_arc_pie);
Imagefilledarc ($image, 100,100,200,120,80,360, $yellow, Img_arc_pie);

Add percent data, of course, when necessary, in batches to carry out a certain operation input to the picture
$str = Iconv ("GBK", "UTF-8", "36%");//If you want to enter Chinese, you need this conversion. Example: Occupy: 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.