首页 | 资讯动态 | linux基础 | 系统管理 | 网络管理 | 编程开发 | linux数据库 | 服务器技术 | linux相关 | linux认证 | 嵌入式 | 下载中心 | 专题 | linux招聘 | HR | 镜像
OKLinux中文技术站
·设为首页
·加入收藏
·联系我们
系统管理: 中文环境 系统管理 桌面应用 内核技术 | Linux基础: 基础入门 安装配置 常用命令 经验技巧 软件应用 | Linux数据库: Mysql Postgre Oracle DB2 Sybase other
网络管理: 网络安全 网络应用 Linux服务器 环境配置 黑客安全 | 编程开发: PHP CC++ Python Perl Shell 嵌入式开发 java jsp | PHP技术: PHP基础 PHP技巧 PHP应用 PHP文摘
搜索中心 Linux招聘 Linux专题 Apache | Linux相关: 硬件相关 Linux解决方案 Linux认证 企业应用 其它Unix | 相关下载: 资料下载 参考手册 开发工具 服务器类 软路由 其它
 技术搜索:
会员中心 注册会员 高级搜索  
  → 当前位置:首页>编程开发>php>php技巧>正文

一个饼状图或柱状图php生成类或例子

http://www.oklinux.cn  2003-04-30  互联网    会员收藏  游客收藏  【 】 
您查看的文章来源于http://www.oklinux.cn

/*-------------------------------------------------------------------------*/
//
// Module Name: 一个3D的饼图类
//
// Author:Avenger([email protected]) Last Modify: 2002-10-30 11:19
// Copyright (c) 2002 by Avenger
/*-------------------------------------------------------------------------*/

//公用函数部分

//把角度转换为弧度
function deg2Arc($degrees) {
return($degrees * (pi()/180.0));
}

//RGB
function getRGB($color){
$R=($color>>16) & 0xff;
$G=($color>>8) & 0xff;
$B=($color) & 0xff;
return (array($R,$G,$B));
}

// 取得在椭圆心为(0,0)的椭圆上 x,y点的值
function pie_point($deg,$va,$vb){
$x= cos(deg2Arc($deg)) * $va;
$y= sin(deg2Arc($deg)) * $vb;
return (array($x, $y));
}

//3D饼图类

class Pie3d{

var $a; //椭圆长半轴
var $b; //椭圆短半轴
var $DataArray; //每个扇形的数据
var $ColorArray; //每个扇形的颜色 要求按照十六进制书写但前面不加0x
var $Fize; //字体大小
//为边缘及阴影为黑色

function Pie3d($pa=60,$pb=30,$sData="100,200,300,400,500", $sColor="ee00ff,dd0000,cccccc,ccff00,00ccff",$fontsize=1) {
$this->a=$pa;
$this->b=$pb;
$this->DataArray=split(",",$sData);
$this->ColorArray=split(",",$sColor);
$this->Fsize=$fontsize;
}

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(){
$fsize=$this->Fsize;
$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, 255, 255, 255));

/*
** 画每一个扇形
*/

$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,$fsize,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);
}
}
}

//输出生成的图片
imagepng($image,'consture.png');
imagedestroy($image);
}//End drawPie()
}//End class
$pie = new Pie3d;
$pie->Pie3d($pa=300,$pb=150,$sData="100,200,300,400,500", $sColor="ee00ff,dd0000,cccccc,ccff00,ddddaa",$fontsize=5);
$pie->DrawPie();
echo '<img src=http://www.ddvip.net/web/php/index2/"consture.png" border=0 alt="交易分析图">';

?>


非常全面的一个php技术网站,

上一篇:一个操作xml的类   下一篇:一个比较完善的购物车类

收藏于收藏夹】 【评论】 【推荐】 【打印】 【关闭
相关文档
·一个操作xml的类
·一个比较完善的购物车类
·一个PHP类
·一个翻页类
·一个访问ACCESS的类
·新作模板处理类
·一个分页导航类
·无限分类&树型论坛的实现
·贴个购物车的类,只用了一个Session
·一个分页导航类示例
·搜索和替换文件或目录的一个好类
·一个改进的UBB类
·数字转换为中文的类
·一个好用的UBB类
·树型结构列出指定目录里所有文件的PHP类
·一个简单编程思想在php与java中的实现比较:日期类
发表评论
密码: 匿名评论
评论内容:

(不超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规)
 
  最新文档
·新版NetBeans让PHP开发更轻松
·PHP之COOKIE支持详解
·PHP中的类
·php中文处理函数
·通过ODBC连接的SQL
·两个日期类
·面向对象编程
·面向过程与面向对象的简单比较
·屏蔽浏览器缓存另类方法
·判断WebSERVER类型
·日历类
·如何文档化你的PHP类
  阅读排行
·终于实现简体转繁体,繁体到转体
·php输出.doc .xls等word和excel文件格
·fckeditor用javascript创建
·PHP5 & Web Services 系统架构图
·PHP之COOKIE支持详解
·用 PHP 读取文件的正确方法
·Linux操作系统下的多线程编程详细解析
·PHP 应用程序配置模式
·利用单元测试对PHP 代码进行检查
·五个常见 PHP 数据库问题
·用PHP读取和编写XML DOM
·使用PHP 快速生成Flash 动画
·数据库存储图片示例。。
·Linux系统下PHP服务器安全配置技巧
·用 PHP V4 开发的代码迁移到 PHP V5
网摘收藏: