php 3D饼图类绘制类函数
发布:smiling 来源: PHP粉丝网 添加日期:2014-08-19 16:20:21 浏览: 评论:0
下面关于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;$i<$DataNumber;$i++) $DataTotal+=$this->DataArray[$i]; //算出数据和
- //填充背境
- imagefill($image, 0, 0, imagecolorallocate($image, 0xFF, 0xFF, 0xFF));
- /*
- ** 画每一个扇形
- */
- $Degrees = 0;
- for($i = 0; $i < $DataNumber; $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<256) $R=$R-60;
- if ($G>60 and $G<256) $G=$G-60;
- if ($B>60 and $B<256) $B=$B-60;
- $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<=180){
- if($EndDegrees<=180){
- for($k = 1; $k < 15; $k++)
- imagearc($image,$PieCenterX, $PieCenterY+$k,$DoubleA, $DoubleB, $StartDegrees, $EndDegrees, $CurrentDarkColor);
- }else{
- for($k = 1; $k < 15; $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
- //开源代码phpfensi.com
- //实现
- $objp = new chart();
- $objp->DrawPie();
Tags: php 3D饼图 php绘制类函数
- 上一篇:php 给图片加上文字水印代码
- 下一篇:php生成图片与验证码图片生成原理
相关文章
- ·打造超酷的PHP数据饼图(2013-11-13)
- ·PHP为图片添加水印的实例(2013-11-14)
- ·php 给图片加灰色透明效果(2013-11-14)
- ·LINUX下PHP网页生成快照(截屏)(xvfb and wkhtmltoimage)(2013-11-14)
- ·php_imagick实现图片剪切、旋转、锐化、减色或增加特效(2013-11-14)
- ·PHP中创建并处理图象(2013-12-08)
- ·在PHP中将图片存放ORACLE中(2013-12-08)
- ·PHP制作图形计数器的例子(2013-12-08)
- ·php生成验证码(2013-12-09)
- ·PHP版的验证码程序(2013-12-10)
- ·php简单支持中文水印程序代码(2013-12-31)
- ·php生成验证码图片从入门和精通教程(2013-12-31)
- ·PHP生成条形码实现程序(2014-01-06)
- ·PHP中生成横状百分比图片实例(2014-01-06)
- ·PHP通过url下载远程图片到本地(2014-01-07)
- ·php批量下载网页图片并替换路径为本地(2014-01-07)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)