Home > Backend Development > PHP Tutorial > Create a cool PHP data pie chart_PHP tutorial

Create a cool PHP data pie chart_PHP tutorial

WBOY
Release: 2016-07-15 13:22:09
Original
1181 people have browsed it

Create a cool PHP data pie chart_PHP tutorial

Source code:

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

//| pie3dfun.PHP//Public functions|

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

define("ANGLE_STEP", 5); //Define the angle step when drawing an elliptical arc

function draw_getdarkcolor($img,$clr) //Find the dark color corresponding to $clr

{

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

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

}

function draw_getexy($a, $b, $d) //Find the ellipse corresponding to angle $d Point coordinates

{

$d = deg2rad($d);

return array(round($a*Cos($d)), round($b* Sin($d)));

}

function draw_arc($img,$ox,$oy,$a,$b,$sd,$ed,$clr) // Elliptic 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);

}


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446994.htmlTechArticleSource code: //+------------------ ------+ //| pie3dfun.PHP//Public functions| //+---------------------+ define("ANGLE_STEP ", 5); //Define the angle step function dra when drawing an elliptical arc...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template