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:画饼状图:先循环画多个圆心在一条直线上的椭圆并填充

 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. 洛谷P1169 棋盘制作(悬线法)

    题目链接:https://www.luogu.org/problemnew/show/P1169 #include<bits/stdc++.h> #define fi first #def ...

  2. 【转】GT 的性能测试方案解析

    前言 本文将整理腾讯GT各个性能测试项的测试方法,目的是为了帮助移动性能专项测试同学快速过一遍腾讯GT各个性能数据是如何获取的.另外对腾讯GT还不了解或者不知道它能做什么的同学可以看看这篇文章:htt ...

  3. mybatis中查询使用#{}和${}的区别

    ${}中的变量什么值,就会简单的替代变量,不会做处理 比如delete * from tb_label where name=${labelname} 如果labelname的值是 something ...

  4. Math的方法;Date的方法;

    Math的方法: (1)弧度的π  Math.PI() (2)返回平方根 Math.sqrt() (3)返回x的绝对值 Mathabs(x) (4)返回x的上舍入 Math.ceil(x) (5)返回 ...

  5. Spring源码-循环依赖源码解读

    Spring源码-循环依赖源码解读 笔者最近无论是看书还是从网上找资料,都没发现对Spring源码是怎么解决循环依赖这一问题的详解,大家都是解释了Spring解决循环依赖的想法(有的解释也不准确,在& ...

  6. Spring MVC 上传和下载文件

    上传文件 Commons FileUpload 元件 Servlet 3.0 本地文件上传特性 HTML 5 下载文件

  7. Python之ftp服务器

    今天把做的ftp服务器过程总结一下,先看看要求 一.需求 1. 用户加密认证 2. 允许同时多用户登录 3. 每个用户有自己的家目录 ,且只能访问自己的家目录 4. 对用户进行磁盘配额,每个用户的可用 ...

  8. cpp 区块链模拟示例(二)工程代码解析

    /* 作 者: itdef 欢迎转帖 请保持文本完整并注明出处 技术博客 http://www.cnblogs.com/itdef/ 技术交流群 群号码:432336863欢迎c c++ window ...

  9. linux安装mysql和httpd

    1.安装前检查是否已经安装[root@localhost1 ~]# rpm -qa |grep mysql 2.安装wget包:[root@localhost1 ~]# yum -y install ...

  10. 使用RabbitMq

    1.配置环境 http://www.cnblogs.com/longlongogo/p/6479424.html 2.安装RabbitMQ https://www.cnblogs.com/longlo ...