欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

打造超酷的PHP数据饼图

程序员文章站 2022-05-16 08:28:05
...

源代码:

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

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

}