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