饼图

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

//| pie3dfun.PHP//公用函数 |

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

define("ANGLE_STEP", 3); //定义画椭圆弧时的角度步长

define("FONT_USED", "C:\WINDOWS\Fonts\simhei.ttf"); // 使用到的字体文件位置

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

}

function draw_sector3d($img, $ox, $oy, $a, $b, $v, $sd, $ed, $clr) //3d扇面

{

draw_sector($img, $ox, $oy, $a, $b, $sd, $ed, $clr);

if($sd<180)

{

list($R, $G, $B) = draw_getdarkcolor($img, $clr);

$clr=imagecolorallocate($img, $R, $G, $B);

if($ed>180) $ed = 180;

list($sx, $sy) = draw_getexy($a,$b,$sd);

$sx += $ox;

$sy += $oy;

list($ex, $ey) = draw_getexy($a, $b, $ed);

$ex += $ox;

$ey += $oy;

imageline($img, $sx, $sy, $sx, $sy+$v, $clr);

imageline($img, $ex, $ey, $ex, $ey+$v, $clr);

draw_arc($img, $ox, $oy+$v, $a, $b, $sd, $ed, $clr);

list($sx, $sy) = draw_getexy($a, $b, ($sd+$ed)/2);

$sy += $oy+$v/2;

$sx += $ox;

imagefill($img, $sx, $sy, $clr);

}

}

function draw_getindexcolor($img, $clr) //RBG转索引色

{

$R = ($clr>>16) & 0xff;

$G = ($clr>>8)& 0xff;

$B = ($clr) & 0xff;

return imagecolorallocate($img, $R, $G, $B);

}

// 绘图主函数,并输出图片

// $datLst 为数据数组, $datLst 为标签数组, $datLst 为颜色数组

// 以上三个数组的维数应该相等

function draw_img($datLst,$labLst,$clrLst,$a=200,$b=90,$v=20,$font=10)

{

$ox = 5+$a;

$oy = 5+$b;

$fw = imagefontwidth($font);

$fh = imagefontheight($font);

$n = count($datLst);//数据项个数

$w = 10+$a*2;

$h = 10+$b*2+$v+($fh+2)*$n;

$img = imagecreate($w, $h);

//转RGB为索引色

for($i=0; $i

$clrLst[$i] = draw_getindexcolor($img,$clrLst[$i]);

$clrbk = imagecolorallocate($img, 0xff, 0xff, 0xff);

$clrt = imagecolorallocate($img, 0x00, 0x00, 0x00);

//填充背景色

imagefill($img, 0, 0, $clrbk);

//求和

$tot = 0;

for($i=0; $i

$tot += $datLst[$i];

$sd = 0;

$ed = 0;

$ly = 10+$b*2+$v;

for($i=0; $i

{

$sd = $ed;

$ed += $datLst[$i]/$tot*360;

//画圆饼

draw_sector3d($img, $ox, $oy, $a, $b, $v, $sd, $ed, $clrLst[$i]); //$sd,$ed,$clrLst[$i]);

//画标签

imagefilledrectangle($img, 5, $ly, 5+$fw, $ly+$fh, $clrLst[$i]);

imagerectangle($img, 5, $ly, 5+$fw, $ly+$fh, $clrt);

//imagestring($img, $font, 5+2*$fw, $ly, $labLst[$i].":".$datLst[$i]."(".(round(10000*($datLst[$i]/$tot))/100)."%)", $clrt);

$str = iconv("GB2312", "UTF-8", $labLst[$i]);

ImageTTFText($img, $font, 0, 5+2*$fw, $ly+13, $clrt, FONT_USED, $str.":".$datLst[$i]."(".(round(10000*($datLst[$i]/$tot))/100)."%)");

$ly += $fh+2;

}

//输出图形

header("Content-type: image/png");

//输出生成的图片

imagepng($img);

}

$datLst = array(30, 20, 20, 20, 10, 20, 10, 20); //数据

$labLst = array("浙江省", "广东省", "上海市", "北京市", "福建省", "江苏省", "湖北省", "安徽省"); //标签

$clrLst = array(0x99ff00, 0xff6666, 0x0099ff, 0xff99ff, 0xffff99, 0x99ffff, 0xff3333, 0x009999);

//画图

draw_img($datLst,$labLst,$clrLst);

?>

php3d饼状图,php 生成饼图 三维饼图相关推荐

  1. python饼状图文字重叠_Matplotlib 绘制饼图解决文字重叠的方法

    在使用matplotlib 绘制饼图的时候有些时候一些数据的比列太小在饼图呈现的效果不明显 很容易被覆盖,为了解决这个问题以下就是我个人的心得. [未解决之前呈现的效果] 可以看到这个饼状图其他和硕士 ...

  2. python 饼状图的生成

    1.生成饼状图需要下载 pygal包.在终端 下载并使用 安装:pip install pygal 2.下面是生成饼状图的代码 3.打开生成出来的饼状图. 这是在pycharm中打开的图片,无显示,因 ...

  3. webchart 生成饼状图 java_WebChart生成折线图,柱状图,饼状图

    折线图形的数据库设计: id int name varchar(50) dataTimedatetime 饼形图和柱状图使用同一个表的数据: id int name varchar(50) shuli ...

  4. css画饼状图圆形,CSS样式圆形饼图百分比

    更新记录 1.0.0(2021-07-27) 简单的CSS样式圆形饼图百分比 平台兼容性 Vue App 微信小程序 支付宝小程序 百度小程序 字节小程序 QQ小程序 快应用 vue2 3.1.0 a ...

  5. mysql生成饼状图_pChart生成饼形图的代码 支持中文

    经常和数据打交道的避免不了生成各种图形,pChart是一个开源的图表生成库,可以生成几十种简单或者复杂或者看不懂的图标,这里的代码是生成饼形图,使用该程序PHP需要开启GD服务,另外pChart支持中 ...

  6. php3d饼状图的教学,php使用Jpgraph创建3D饼形图效果示例

    本文实例讲述了php使用Jpgraph创建3D饼形图效果.分享给大家供大家参考,具体如下: 用Jpgraph类库制作统计图功能及其强大,不仅可以绘制平面图形,而且可以绘制具有3D效果的图形.直接使用G ...

  7. python饼状图顺时针_Python matplotlib顺时针饼图

    我正在研究Python及其matplotlib库,如何创建以下图表,以便第一个切片从顶部开始并向右(顺时针)而不是向左(逆时针)移动: 代码:import matplotlib.pyplot as p ...

  8. java 生成柱状图、饼状图等图片保存至word文档

    写在前面,springboot pom 中引入下面就可以了,省了在csdn找包很麻烦. <dependency><artifactId>jfreechart</artif ...

  9. echarts 饼状图 label 既在内部显示数值(百分比),又显示外部指示线

    需求 项目开发中,产品经理绘制的原型图中,需要前端实现一个饼状图,且既在饼图内部中 显示 百分比,又显示 外部指示线及数值,效果如下图所示: 查了下 Echarts 官网文档,需要配置 series ...

最新文章

  1. TCP协议的特点和TCP报文段格式
  2. mpeg b帧 编码 matlab,一种基于压缩域的镜头检测算法
  3. 解决: pip install 由于目标计算机积极拒绝,无法连接
  4. matlab求微分方程同届,Matlab学习——求解微分方程(组)
  5. Source Xref 与 JavaDocs 学习理解
  6. JavaScript 笔记2
  7. 不一般的电路设计——什么是电压采集采样?
  8. Linux如何一键配置网络ip?
  9. 控制教程 —— 介绍篇:6.状态空间控制器设计
  10. git diffmerge合并
  11. c语言程序的函数组成包括两个部分,c语言函数由哪两部分组成
  12. java不支持bks,java不支持bks
  13. STM32 F103 外部晶振8M改为12M
  14. OLAP和OLTP的介绍
  15. Python中的GPS轨迹聚类
  16. PP模块常用数据库表
  17. 深信服---之上网行为管理
  18. AbstractHandlerMapping$PreFlightHandler can‘t be cast to springframework.web.method.HandlerMethod
  19. 揭秘阿里VR电商购物
  20. python dataframe 按照某一列降序

热门文章

  1. Ng第一课:引言(Introduction)
  2. 解决qt程序运行时的cannot create Qt for Embedded Linux data directory: /tmp/qtembedded-0
  3. Linux操作命令(二)
  4. attribute property --- jquery attr() prop()
  5. LOL(英雄联盟)提示不支持虚拟机登录,解决方法
  6. jmeter报“msg“:“Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported“的解决方法
  7. 【报告分享】2020快手电商生态报告.pdf(附下载链接)
  8. 大神齐聚,算法大赛复赛晋级名单揭晓!
  9. linux报mce清除不良代码,如何分析系统MCE异常?
  10. 单例模式-Java实现-非延迟加载、延迟加载