Php3D pie chart class drawing class function _ PHP Tutorial

Source: Internet
Author: User
Php3D pie chart class painting class function. The implementation principle of the php3D pie chart class function is to draw a 3D pie chart code based on parameters such as the long half-axis of the ellipse. The following section describes how to create a 3D pie chart class function in php. the following section describes how to use a 3D pie chart class function to create a 3D pie chart based on parameters such as // Long and semi-axis of the ellipse. code.

The following is a php Tutorial on how to implement a 3D pie chart class function based on parameters such as // long and half-axis of the ellipse.3D pie chart.

Class chart {

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

Function chart ($ pa = 100, $ pb = 60, $ sData = "100,200,300,400,500,300", $ sColor = "ee00ff, dd0000, cccccccc, ccff00, 00 ccff, ccff00 ")
{
$ This-> a = $ pa;
$ This-> B = $ pb;
$ This-> DataArray = split (",", $ sData );
$ This-> ColorArray = split (",", $ sColor );
}

Function setA ($ v ){
$ This-> a = $ v;
}

Function getA (){
Return $ this->;
}

Function setB ($ v ){
$ This-> B = $ v;
}

Function getB (){
Return $ this-> B;
}

Function setDataArray ($ v ){
$ This-> DataArray = split (",", $ v );
}

Function getDataArray ($ v ){
Return $ this-> DataArray;
}

Function setColorArray ($ v ){
$ This-> ColorArray = split (",", $ v );
}

Function getColorArray (){
Return $ this-> ColorArray;
}


Function DrawPie (){
$ Image = imagecreate ($ this-> a * 2 + 40, $ this-> B * 2 + 40 );
$ PieCenterX = $ this-> a + 10;
$ PieCenterY = $ this-> B + 10;
$ DoubleA = $ this-> a * 2;
$ DoubleB = $ this-> B * 2;
List ($ R, $ G, $ B) = getRGB (0 );
$ ColorBorder = imagecolorallocate ($ image, $ R, $ G, $ B );
$ DataNumber = count ($ this-> DataArray );

// $ DataTotal
For ($ I = 0; $ I <$ DataNumber; $ I ++) $ DataTotal + = $ this-> DataArray [$ I]; // calculates the data and

// Fill in the background
Imagefill ($ image, 0, 0, imagecolorallocate ($ image, 0xFF, 0xFF, 0xFF ));

/*
** Draw each slice
*/
$ Degrees = 0;
For ($ I = 0; $ I <$ DataNumber; $ I ++ ){
$ StartDegrees = round ($ Degrees );
$ Degrees + = ($ this-> DataArray [$ I]/$ DataTotal) * 360 );
$ EndDegrees = round ($ Degrees );
$ Percent = number_format ($ this-> DataArray [$ I]/$ DataTotal * 100, 1 );
List ($ R, $ G, $ B) = getRGB (hexdec ($ this-> ColorArray [$ I]);
$ CurrentColor = imagecolorallocate ($ image, $ R, $ G, $ B );
If ($ R> 60 and $ R <256) $ R = $ R-60;
If ($ G> 60 and $ G <256) $ G = $ G-60;
If ($ B> 60 and $ B <256) $ B = $ B-60;
$ CurrentDarkColor = imagecolorallocate ($ image, $ R, $ G, $ B );
// Draw slice arc
Imagearc ($ image, $ PieCenterX, $ PieCenterY, $ DoubleA, $ DoubleB, $ StartDegrees, $ EndDegrees, $ CurrentColor );
// Draw a straight line
List ($ ArcX, $ ArcY) = pie_point ($ StartDegrees, $ this-> a, $ this-> B );
Imageline ($ image, $ PieCenterX, $ PieCenterY, floor ($ PieCenterX + $ ArcX), floor ($ PieCenterY + $ ArcY), $ CurrentColor );
// Draw a straight line
List ($ ArcX, $ ArcY) = pie_point ($ EndDegrees, $ this-> a, $ this-> B );
Imageline ($ image, $ PieCenterX, $ PieCenterY, ceil ($ PieCenterX + $ ArcX), ceil ($ PieCenterY + $ ArcY), $ CurrentColor );
// Fill the slice
$ MidPoint = round ($ EndDegrees-$ StartDegrees)/2) + $ StartDegrees );
List ($ ArcX, $ ArcY) = Pie_point ($ MidPoint, $ this-> a * 3/4, $ this-> B * 3/4 );

Imagefilltoborder ($ image, floor ($ PieCenterX + $ ArcX), floor ($ PieCenterY + $ ArcY), $ CurrentColor, $ CurrentColor );
Imagestring ($ image, 2, floor ($ PieCenterX + $ ArcX-5), floor ($ PieCenterY + $ ArcY-5), $ percent. "%", $ colorBorder );

// 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


// Implementation

$ Objp = new chart ();
$ Objp-> DrawPie ();

3D pie chart class function implementation principle is to draw a 3D pie chart code based on parameters such as // Long half axis of the elliptical. The following section describes how to implement the class functions of 3D pie chart in php tutorials...

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.