Create a superb PHP Data pie chart _ PHP Tutorial

Source: Internet
Author: User
Create a cool PHP Data pie chart. Source code: + ---------------------- + | pie3dfun. PHP public function | + ------------------------ + define (ANGLE_STEP, 5); define the angle step functiondra when drawing an elliptical arc

Source code:

// + ------------------------ +

// | Pie3dfun. PHP // public function |

// + ------------------------ +

Define ("ANGLE_STEP", 5); // defines the angle step when an elliptical arc is drawn.

Function draw_getdarkcolor ($ img, $ clr) // Evaluate the dark color of $ clr

{

$ Rgb = imagecolorsforindex ($ img, $ clr );

Return array ($ rgb ["red"]/2, $ rgb ["green"]/2, $ rgb ["blue"]/2 );

}

Function draw_getexy ($ a, $ B, $ d) // calculates the coordinate of the point on the elliptic corresponding to the angle $ d.

{

$ D = deg 2rad ($ d );

Return array (round ($ a * Cos ($ d), round ($ B * Sin ($ d )));

}

Function draw_arc ($ img, $ ox, $ oy, $ a, $ B, $ sd, $ ed, $ clr) // elliptical arc function

{

$ N = ceil ($ ed-$ sd)/ANGLE_STEP );

$ D = $ sd;

List ($ x0, $ y0) = draw_getexy ($ a, $ B, $ d );

For ($ I = 0; $ I <$ n; $ I ++)

{

$ D = ($ d + ANGLE_STEP)> $ ed? $ Ed :( $ d + ANGLE_STEP );

List ($ x, $ y) = draw_getexy ($ a, $ B, $ d );

Imageline ($ img, $ x0 + $ ox, $ y0 + $ oy, $ x + $ ox, $ y + $ oy, $ clr );

$ X0 = $ x;

$ Y0 = $ y;

}

}

Function draw_sector ($ img, $ ox, $ oy, $ a, $ B, $ sd, $ ed, $ clr) // draw a fan

{

$ N = ceil ($ ed-$ sd)/ANGLE_STEP );

$ D = $ sd;

List ($ x0, $ y0) = draw_getexy ($ a, $ B, $ d );

Imageline ($ img, $ x0 + $ ox, $ y0 + $ oy, $ ox, $ oy, $ clr );

For ($ I = 0; $ I <$ n; $ I ++)

{

$ D = ($ d + ANGLE_STEP)> $ ed? $ Ed :( $ d + ANGLE_STEP );

List ($ x, $ y) = draw_getexy ($ a, $ B, $ d );

Imageline ($ img, $ x0 + $ ox, $ y0 + $ oy, $ x + $ ox, $ y + $ oy, $ clr );

$ X0 = $ x;

$ Y0 = $ y;

}

Imageline ($ img, $ x0 + $ ox, $ y0 + $ oy, $ ox, $ oy, $ clr );

List ($ x, $ y) = draw_getexy ($ a/2, $ B/2, ($ d + $ sd)/2 );

Imagefill ($ img, $ x + $ ox, $ y + $ oy, $ clr );

}


Certificate // + ------------------------ + // | pie3dfun. PHP // public function | // + ------------------------ + define ("ANGLE_STEP", 5); // defines the angle step function dra when an elliptical arc is drawn...

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.