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() 以 cx,cy(图像左上角为 0, 0)为中心在 image 所代表的图像中画一个椭圆弧。w 和 h 分别指定了椭圆的宽度和高度,起始和结束点以 s 和 e 参数以角度指定。0°位于三点钟位置,以顺时针方向绘画。

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

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

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:指明用直线将起始和结束点与中心点相连

简单事例:

前台代码:

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

前台界面:

后台PHP代码:

 <?php 

 //创建画布
$image=imagecreatetruecolor(200,200); //定义颜色
$red=imagecolorallocate($image, 255, 0, 0);
$darkred=imagecolorallocate($image, 102, 0, 0); $blue=imagecolorallocate($image, 0, 0, 255);
$darkblue=imagecolorallocate($image, 0, 51, 102);; $green=imagecolorallocate($image, 0, 255, 0);
$darkgreen=imagecolorallocate($image, 51, 102, 51); $gray=imagecolorallocate($image, 125, 125, 125);
$darkgray=imagecolorallocate($image, 102, 102, 102); $anhui=$_POST['anhui'];
$jilin=$_POST['jilin'];
$beijing=$_POST['beijing'];
$zhejiang=$_POST['zhejiang']; $count=$anhui+$beijing+$jilin+$zhejiang; //循环画饼状图
for($i=100;$i>85;$i--){
imagefilledarc($image, 100, $i, 150, 100, 0, ($anhui/$count)*360, $darkgray, IMG_ARC_PIE);
imagefilledarc($image, 100, $i, 150, 100, ($anhui/$count)*360, (($anhui+$jilin)/$count)*360, $darkblue, IMG_ARC_PIE);
imagefilledarc($image, 100, $i, 150, 100, (($anhui+$jilin)/$count)*360, (($anhui+$jilin+$beijing)/$count)*360, $darkgreen, IMG_ARC_PIE);
imagefilledarc($image, 100, $i, 150, 100, (($anhui+$jilin+$beijing)/$count)*360, 360, $darkred, IMG_ARC_PIE);
}
imagefilledarc($image, 100, 85, 150, 100, 0, ($anhui/$count)*360, $gray, IMG_ARC_PIE);
imagefilledarc($image, 100, 85, 150, 100, ($anhui/$count)*360, (($anhui+$jilin)/$count)*360, $blue, IMG_ARC_PIE);
imagefilledarc($image, 100, 85, 150, 100, (($anhui+$jilin)/$count)*360, (($anhui+$jilin+$beijing)/$count)*360, $green, IMG_ARC_PIE);
imagefilledarc($image, 100, 85, 150, 100, (($anhui+$jilin+$beijing)/$count)*360, 360, $red, IMG_ARC_PIE); header("Content-type: image/png"); imagepng($image); imagedestroy($image); ?>

后台处理结果:

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. Ubuntu安装pyucharm的专业版本

    看到了不错的教程,亲测有效. https://www.cnblogs.com/huozf/p/9304396.html

  2. ubuntu系统中安装eclipse

    具体可以看这篇博文 .https://www.cnblogs.com/sanduo1314/articles/5137090.html 然后再/usr/share/applications中找到ecl ...

  3. FP数据库配置文件

  4. 手游开发之lua的table 元表的运用

    元表在项目中的运用,其中就包括元方法这点.元方法是指__index和__newIndex,下面我总结下,更详细的例子讲解可以参考<lua程序设计 第2版>的第13章内容.长h短说,简言之有 ...

  5. ROLAP、MOLAP和HOLAP区别

    对没有使用过数据仓库的人,对这三个概念确实是有点混淆不清.包括我自己本身不是做数据仓库出身,所以实际上是从实践出发,理论基础是有点匮乏的. 一.基本概念 1. OLAP OLAP(on-Line An ...

  6. 【读书笔记】深入应用C++11代码优化与工业级应用 读书笔记01

    第一章 使用C++11让程序更简洁.更现代 1.1  类型推导 1.1.1  auto类型推导 1.auto关键字的新意义 不同于python等动态类型语言的运行时进行变量类型的推导,隐式类型定义的类 ...

  7. Linux下查看磁盘挂载的几种方法

    Linux下查看磁盘挂载的几种方法 第一种方法:df命令 # df -hT Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtm ...

  8. Linux驱动之一个简单的输入子系统程序编写

    的在Linux驱动之输入子系统简析已经分析过了输入子系统的构成,它是由设备层.核心层.事件层共同组成的.其中核心层提供一些设备层与事件层公用的函数,比如说注册函数.反注册函数.事件到来的处理函数等等: ...

  9. MySQL往表里插入千条数据 存储过程

    工作中遇到的问题,先记录一下,方便以后查看 存在两张表,user表和friend表 user表部分字段,如上图 friend表部分字段,如上图 往friend表插入千条数据,friend表中的user ...

  10. javascript函数闭包(closure)

    一,首先感受下javascript函数的闭包 二,闭包 1,定义:闭包就是能够读取其他函数内部变量的函数,由于在javascript语言中,只有在函数内部的子函数才能够读取局部变量,因此可以把闭包简单 ...