下面关于php教程 3d饼图类绘制类函数实现原理是根据//椭圆长半轴 等参数绘制一个3d饼图形的代码。
class chart{
var $a; //椭圆长半轴
var $b; //椭圆短半轴
var $dataarray; //每个扇形的数据
var $colorarray; //每个扇形的颜色 要求按照十六进制书写但前面不加0x
//为边缘及阴影为黑色
function chart($pa=100,$pb=60,$sdata=100,200,300,400,500,300, $scolor=ee00ff,dd0000,cccccc,ccff00,00ccff,ccff00)
{
$this->a=$pa;
$this->b=$pb;
$this->dataarray=split(,,$sdata);
$this->colorarray=split(,,$scolor);
}
function seta($v){
$this->a=$v;
}
function geta(){
return $this->a;
}
function setb($v){
$this->b=$v;
}
function getb(){
return $this->b;
}
function setdataarray($v){
$this->dataarray=split(,,$v);
}
function getdataarray($v){
return $this->dataarray;
}
function setcolorarray($v){
$this->colorarray=split(,,$v);
}
function getcolorarray(){
return $this->colorarray;
}
function drawpie(){
$image=imagecreate($this->a*2+40,$this->b*2+40);
$piecenterx=$this->a+10;
$piecentery=$this->b+10;
$doublea=$this->a*2;
$doubleb=$this->b*2;
list($r,$g,$b)=getrgb(0);
$colorborder=imagecolorallocate($image,$r,$g,$b);
$datanumber=count($this->dataarray);
//$datatotal
for($i=0;$idataarray[$i]; //算出数据和
//填充背境
imagefill($image, 0, 0, imagecolorallocate($image, 0xff, 0xff, 0xff));
/*
** 画每一个扇形
*/
$degrees = 0;
for($i = 0; $i $startdegrees = round($degrees);
$degrees += (($this->dataarray[$i]/$datatotal)*360);
$enddegrees = round($degrees);
$percent = number_format($this->dataarray[$i]/$datatotal*100, 1);
list($r,$g,$b)=getrgb(hexdec($this->colorarray[$i]));
$currentcolor=imagecolorallocate($image,$r,$g,$b);
if ($r>60 and $r if ($g>60 and $g if ($b>60 and $b $currentdarkcolor=imagecolorallocate($image,$r,$g,$b);
//画扇形弧
imagearc($image,$piecenterx,$piecentery,$doublea,$doubleb,$startdegrees,$enddegrees,$currentcolor);
//画直线
list($arcx, $arcy) = pie_point($startdegrees , $this->a , $this->b);
imageline($image,$piecenterx,$piecentery,floor($piecenterx + $arcx),floor($piecentery + $arcy),$currentcolor);
//画直线
list($arcx, $arcy) = pie_point($enddegrees,$this->a , $this->b);
imageline($image,$piecenterx,$piecentery,ceil($piecenterx + $arcx),ceil($piecentery + $arcy),$currentcolor);
//填充扇形
$midpoint = round((($enddegrees - $startdegrees)/2) + $startdegrees);
list($arcx, $arcy) = pie_point($midpoint, $this->a*3/4 , $this->b*3/4);
imagefilltoborder($image,floor($piecenterx + $arcx),floor($piecentery + $arcy), $currentcolor,$currentcolor);
imagestring($image,2,floor($piecenterx + $arcx-5),floor($piecentery + $arcy-5),$percent.%,$colorborder);
//画阴影
if ($startdegrees>=0 and $startdegrees if($enddegrees for($k = 1; $k imagearc($image,$piecenterx, $piecentery+$k,$doublea, $doubleb, $startdegrees, $enddegrees, $currentdarkcolor);
}else{
for($k = 1; $k imagearc($image,$piecenterx, $piecentery+$k,$doublea, $doubleb, $startdegrees, 180, $currentdarkcolor);
}
}
}
/*到此脚本已经生了一幅图像了
**现在需要的是把它发到浏览器上,重要的一点是要将标头发给浏览器,让它知道是一个gif文件。不然的话你只能看到一堆奇怪的乱码
*/
//输出生成的图片
header(content-type: image/gif);
imagegif($image);
imagedestroy($image);
}//end drawpie()
}//end class
//实现
$objp = new chart();
$objp->drawpie();
http://www.bkjia.com/phpjc/633048.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/633048.htmltecharticle下面关于php 3d饼图类绘制类函数实现原理是根据//椭圆长半轴 等参数绘制一个3d饼图形的代码。 下面关于php教程 3d饼图类绘制类函数实现原...
