1:画矩形:

imagerectangle ( resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $col )

imagerectangle()col 颜色在 image 图像中画一个矩形,其左上角坐标为 x1, y1,右下角坐标为 x2, y2。图像的左上角坐标为 0, 0。

2:画椭圆:

imageellipse ( resource $image , int $cx , int $cy , int $width , int $height , int $color )

cx中间的 X 坐标。cy中间的 Y 坐标。width椭圆的宽度。height椭圆的高度。color椭圆的颜色。

3:画椭圆弧:

imagearc ( resource $image , int $cx , int $cy , int $w , int $h , int $s , int $e , int $color )(即在椭圆中截取一定的弧度)

imagearc()cxcy(图像左上角为 0, 0)为中心在 image 所代表的图像中画一个椭圆弧。wh 分别指定了椭圆的宽度和高度,起始和结束点以 se 参数以角度指定。0°位于三点钟位置,以顺时针方向绘画。

4:画饼状图:先循环画多个圆心在一条直线上的椭圆并填充

  1. for($i=100;$i>50;$i--){
  2. imagefilledarc($image, 150, $i, 150, 100, 0, 270, $gray,IMG_ARC_EDGED );
  3. }

imagefilledarc ( resource $image , int $cx , int $cy , int $width , int $height , int $start , int $end , int $color , int $style )

cx:中间的 x 坐标。cy:中间的 y 坐标。width:椭圆弧的宽度。height:椭圆弧的高度。start:起点角度。end:终点角度。 0°color:颜色标识符。

style:

  1. IMG_ARC_PIE  :则产生圆形边界并填充
  2. IMG_ARC_CHORD :只是用直线连接了起始和结束点并填充
  3. IMG_ARC_NOFILL:则产生圆形边界不填充
  4. IMG_ARC_EDGED:指明用直线将起始和结束点与中心点相连

简单事例:

前台代码:

  1. <div style="width:300px;height:400px;border:1px solid gray;margin:auto;">
  2. <h2 style="text-align:center">全校学生分布统计</h2>
  3. <center>
  4. <form action="11Pro.php" method="post">
  5. 安徽:<input type="text" name="anhui"><br/>
  6. 浙江:<input type="text" name="zhejiang"><br/>
  7. 吉林:<input type="text" name="jilin"><br/>
  8. 北京:<input type="text" name="beijing"><br/><br/>
  9. <input style="width:160px;" type="submit" value="生成饼状图"><br/>
  10. <input style="width:160px;" type="reset" value="重置">
  11. </form>
  12. </center>
  13. </div>

前台界面:

后台PHP代码:

  1. <?php
  2.  
  3. //创建画布
  4. $image=imagecreatetruecolor(200,200);
  5.  
  6. //定义颜色
  7. $red=imagecolorallocate($image, 255, 0, 0);
  8. $darkred=imagecolorallocate($image, 102, 0, 0);
  9.  
  10. $blue=imagecolorallocate($image, 0, 0, 255);
  11. $darkblue=imagecolorallocate($image, 0, 51, 102);;
  12.  
  13. $green=imagecolorallocate($image, 0, 255, 0);
  14. $darkgreen=imagecolorallocate($image, 51, 102, 51);
  15.  
  16. $gray=imagecolorallocate($image, 125, 125, 125);
  17. $darkgray=imagecolorallocate($image, 102, 102, 102);
  18.  
  19. $anhui=$_POST['anhui'];
  20. $jilin=$_POST['jilin'];
  21. $beijing=$_POST['beijing'];
  22. $zhejiang=$_POST['zhejiang'];
  23.  
  24. $count=$anhui+$beijing+$jilin+$zhejiang;
  25.  
  26. //循环画饼状图
  27. for($i=100;$i>85;$i--){
  28. imagefilledarc($image, 100, $i, 150, 100, 0, ($anhui/$count)*360, $darkgray, IMG_ARC_PIE);
  29. imagefilledarc($image, 100, $i, 150, 100, ($anhui/$count)*360, (($anhui+$jilin)/$count)*360, $darkblue, IMG_ARC_PIE);
  30. imagefilledarc($image, 100, $i, 150, 100, (($anhui+$jilin)/$count)*360, (($anhui+$jilin+$beijing)/$count)*360, $darkgreen, IMG_ARC_PIE);
  31. imagefilledarc($image, 100, $i, 150, 100, (($anhui+$jilin+$beijing)/$count)*360, 360, $darkred, IMG_ARC_PIE);
  32. }
  33. imagefilledarc($image, 100, 85, 150, 100, 0, ($anhui/$count)*360, $gray, IMG_ARC_PIE);
  34. imagefilledarc($image, 100, 85, 150, 100, ($anhui/$count)*360, (($anhui+$jilin)/$count)*360, $blue, IMG_ARC_PIE);
  35. imagefilledarc($image, 100, 85, 150, 100, (($anhui+$jilin)/$count)*360, (($anhui+$jilin+$beijing)/$count)*360, $green, IMG_ARC_PIE);
  36. imagefilledarc($image, 100, 85, 150, 100, (($anhui+$jilin+$beijing)/$count)*360, 360, $red, IMG_ARC_PIE);
  37.  
  38. header("Content-type: image/png");
  39.  
  40. imagepng($image);
  41.  
  42. imagedestroy($image);
  43.  
  44. ?>

后台处理结果:

PHP画矩形,椭圆,圆,画椭圆弧 ,饼状图的更多相关文章

  1. PHP imagearc - 画椭圆弧

    imagearc — 用于画椭圆弧.高佣联盟 www.cgewang.com 语法 bool imagearc ( resource $image , int $cx , int $cy , int ...

  2. canvas+js画饼状图

    效果: 源码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...

  3. 利用Tkinter和matplotlib两种方式画饼状图

    当我们学习python的时候,总会用到一些常用的模块,接下来我就详细讲解下利用两种不同的方式画饼状图.首先利用[Tkinter]中的canvas画布来画饼状图: from tkinter import ...

  4. vue中使用echarts画饼状图

    echarts的中文文档地址:https://echarts.baidu.com/tutorial.html#5%20%E5%88%86%E9%92%9F%E4%B8%8A%E6%89%8B%20EC ...

  5. PHP实现动态生成饼状图 (转载)

    <?php //变量定义,画椭圆弧时的角度大小 define("ANGLELENGTH", 10); /** * 绘制图片 * @param $title 3D图的标题 * ...

  6. 自定义View饼状图的绘制

    package com.loaderman.customviewdemo; import android.content.Context; import android.graphics.Canvas ...

  7. canvas图表详解系列(3):动态饼状图(原生Js仿echarts饼状图)

    本章建议学习时间4小时 学习方式:详细阅读,并手动实现相关代码(如果没有canvas基础,需要先学习前面的canvas基础笔记) 学习目标:此教程将教会大家如何使用canvas绘制各种图表,详细分解步 ...

  8. iOS:使用贝塞尔曲线绘制图表(折线图、柱状图、饼状图)

    1.介绍: UIBezierPath :画贝塞尔曲线的path类 UIBezierPath定义 : 贝赛尔曲线的每一个顶点都有两个控制点,用于控制在该顶点两侧的曲线的弧度. 曲线的定义有四个点:起始点 ...

  9. WPF 饼状图,柱形图,折线图 (3 饼状图)

    网址:https://www.cnblogs.com/CSSZBB/p/12746214.html 饼状图相对来说复杂一些.因为需要计算很多坐标,线来看下这个列子. 圆首先想到Ellipse.但是El ...

随机推荐

  1. R语言-简单模型画图

    1.回归拟合 > plot(mtcars$mpg~mtcars$disp) > lmfit<-lm(mtcars$mpg~mtcars$disp) #线性回归模型 > abli ...

  2. MyBatis :Insert (返回主键、批量插入)

    一.前言    数据库操作怎能少了INSERT操作呢?下面记录MyBatis关于INSERT操作的笔记,以便日后查阅. 二.insert元素 属性详解   其属性如下: parameterType , ...

  3. sqlserver 更新通过 select 查询出的结果集

    update Babies set BirthOrder =tb.sn from Babies b1, (select ROW_NUMBER() over (partition by familyid ...

  4. django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call

    Error info: django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, ...

  5. JS同步与异步;

    JS的同步与异步 同步:代买从上往下的执行 异步:每个模块各执行各的,同时执行,互不干扰 四个异步事件:(1)定时器(2)ajax(3)时间的绑定(4)回调函数 现在用定时器来说一说setTimeOu ...

  6. Quartz.Net进阶之三:SimpleTrigger详述

    以前都是将所有的内容放在一篇文章里,就会导致文章很长,对于学习的人来说,有时候这也是一个障碍.所以,以后我的写作习惯,我就会把我写的文章缩短,但是内容不会少,内容更集中.这样,学习起来也不会很累,很容 ...

  7. 选择困难症的福音——团队Scrum冲刺阶段-Day 4

    选择困难症的福音--团队Scrum冲刺阶段-Day 4 今日进展 编写提问部分 做了不同问题所对应的游戏选项,但关于游戏分类的界面还没有做完 增加功能 昨天在主界面增加"关于我们" ...

  8. django by example 第五章 No module named 'sorl-thumbnail'

    描述:按照原书在settings的installed apps中加入sorl-thumbnail后同步数据库显示No module named 'sorl-thumbnail' 解决方案: 根据官方文 ...

  9. Postman入门使用

    Postman 是一个很强大的 API调试.Http请求的工具,方便易用,毋庸置疑. 1.Postman安装 a. 打开谷歌浏览器 b. 进入设置界面 c. 选择扩展程序 d. 选择chrome网上应 ...

  10. 【转】nc 使用说明

    netcat是网络工具中的瑞士军刀,它能通过TCP和UDP在网络中读写数据.通过与其他工具结合和重定向,你可以在脚本中以多种方式使用它.使用netcat命令所能完成的事情令人惊讶. netcat所做的 ...