Home > php教程 > php手册 > body text

打造超酷的PHP数据饼图

WBOY
Release: 2016-06-13 10:59:27
Original
1118 people have browsed it

源代码:

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

//| pie3dfun.PHP//公用函数 |

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

define("ANGLE_STEP", 5); //定义画椭圆弧时的角度步长

function draw_getdarkcolor($img,$clr) //求$clr对应的暗色

{

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

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

}

function draw_getexy($a, $b, $d) //求角度$d对应的椭圆上的点坐标

{

$d = deg2rad($d);

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

}

function draw_arc($img,$ox,$oy,$a,$b,$sd,$ed,$clr) //椭圆弧函数

{

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

$d = $sd;

list($x0,$y0) = draw_getexy($a,$b,$d);

for($i=0; $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) //画扇面

{

$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

{

$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);

}


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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!