PHP object programming to implement a 3D pie chart
Source: Internet
Author: User
PHP object programming to implement a 3D pie chart & lt ;? Php <br/> // public function <br/> // converts degrees to radians <br/> functiondeg
// Public functions
// Converts degrees to radians
Function deg2Arc ($ degrees ){
Return ($ degrees * (pi ()/180.0 ));
}
// RGB
Function getRGB ($ color ){
$ R = ($ color> 16) & 0xff;
$ G = ($ color> 8) & 0xff;
$ B = ($ color) & 0xff;
Return (array ($ R, $ G, $ B ));
}
// Obtain the values of the x and y points on an elliptical center (0, 0 ).
Function pie_point ($ deg, $ va, $ vb ){
$ X = cos (deg2Arc ($ deg) * $ va;
$ Y = sin (deg2Arc ($ deg) * $ vb;
Return (array ($ x, $ y ));
}
// 3D pie chart
Class Pie3d {
Var $ a; // The long half-axis of the ellipse.
Var $ B; // specifies the shorter half-axis of an ellipse.
Var $ DataArray; // data of each sector
Var $ ColorArray; // The color of each slice must be written in hexadecimal format, but 0x is not added before.
// Black for the edge and shadow
// Shadow
If ($ StartDegrees> = 0 and $ StartDegrees <= 180 ){
If ($ EndDegrees <= 180 ){
For ($ k = 1; $ k <15; $ k ++)
Imagearc ($ image, $ PieCenterX, $ PieCenterY + $ k, $ DoubleA, $ DoubleB, $ StartDegrees, $ EndDegrees, $ CurrentDarkColor );
} Else {
For ($ k = 1; $ k <15; $ k ++)
Imagearc ($ image, $ PieCenterX, $ PieCenterY + $ k, $ DoubleA, $ DoubleB, $ StartDegrees, 180, $ CurrentDarkColor );
}
}
}
/* This script has produced an image.
** What we need now is to send it to the browser. the important thing is to send the header to the browser so that it knows that it is a GIF file. Otherwise, you can only see a bunch of strange garbled characters.
*/
// Output the generated image
Header ("Content-type: image/gif ");
Imagegif ($ image );
Imagedestroy ($ image );
} // End drawPie ()
} // End class
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.