php代码:--------------------------------------------------------------------------------
/*-------------------------------------------------------------------------*/
//
// module name: 一个3d的饼图类
//
// author:avenger(avenger@php.net) 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;$idataarray[$i]; //算出数据和
//填充背景
imagefill($image, 0, 0, imagecolorallocate($image, 255, 255, 255));
/*
** 画每一个扇形
*/
$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 $rif ($g>60 and $gif ($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,$fsize,floor($piecenterx + $arcx-5),floor($piecentery + $arcy-5),$percent."%",$colorborder);
//画阴影
if ($startdegrees>=0 and $startdegreesif($enddegreesfor($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);
}
}
}
//输出生成的图片
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 '
';
?>
0
0
相关文章
如何在 PHP 中动态构建并过滤多维子数组,避免空键与空值
如何在 PHP 中动态构建并过滤多维子数组,剔除空值项
如何在PHP中将MySQL存储的Base64图片用作网页背景图
如何在PHP中将MySQL存储的Base64图片用作网页背景图像
如何使用 PHP 基于上传的 PDF 模板动态生成新 PDF 文档
相关标签:
本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门AI工具
相关专题
本专题围绕 Archive of Our Own(AO3)官网入口展开,系统整理 AO3 最新可用官网地址、网页版访问方式、正确打开链接的方法,并详细讲解 AO3 中文界面设置、阅读语言切换及基础使用流程,帮助用户稳定访问 AO3 官网,高效完成中文阅读与作品浏览。
91
2026.02.02
本专题聚合极兔快递、京东快递、中通快递、圆通快递、韵达快递等主流物流平台的单号查询与运单追踪内容,重点解决单号查询、手机号查物流、官网入口直达、包裹进度实时追踪等高频问题,帮助用户快速获取最新物流状态,提升查件效率与使用体验。
27
2026.02.02
本专题系统讲解 Golang 在 WebAssembly(WASM)开发中的实践方法,涵盖 WASM 基础原理、Go 编译到 WASM 的流程、与 JavaScript 的交互方式、性能与体积优化,以及典型应用场景(如前端计算、跨平台模块)。帮助开发者掌握 Go 在新一代 Web 技术栈中的应用能力。
11
2026.02.02
本专题聚焦 PHP Swoole 扩展在高性能服务端开发中的应用,系统讲解协程模型、异步IO、TCP/HTTP/WebSocket服务器、进程与任务管理、常驻内存架构设计。通过实战案例,帮助开发者掌握 使用 PHP 构建高并发、低延迟服务端应用的工程化能力。
5
2026.02.02
本专题系统讲解 Java 通过 JNI 调用 C/C++ 本地代码的核心机制,涵盖 JNI 基本原理、数据类型映射、内存管理、异常处理、性能优化策略以及典型应用场景(如高性能计算、底层库封装)。通过实战示例,帮助开发者掌握 Java 与本地代码混合开发的完整流程。
5
2026.02.02
热门下载
相关下载
精品课程
最新文章





