PHP画矩形,椭圆,圆,画椭圆弧 ,饼状图
1:画矩形:
$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:画椭圆弧:
$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:
IMG_ARC_PIE :则产生圆形边界并填充IMG_ARC_CHORD :只是用直线连接了起始和结束点并填充IMG_ARC_NOFILL:则产生圆形边界不填充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画矩形,椭圆,圆,画椭圆弧 ,饼状图的更多相关文章
- PHP imagearc - 画椭圆弧
imagearc — 用于画椭圆弧.高佣联盟 www.cgewang.com 语法 bool imagearc ( resource $image , int $cx , int $cy , int ...
- canvas+js画饼状图
效果: 源码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...
- 利用Tkinter和matplotlib两种方式画饼状图
当我们学习python的时候,总会用到一些常用的模块,接下来我就详细讲解下利用两种不同的方式画饼状图.首先利用[Tkinter]中的canvas画布来画饼状图: from tkinter import ...
- vue中使用echarts画饼状图
echarts的中文文档地址:https://echarts.baidu.com/tutorial.html#5%20%E5%88%86%E9%92%9F%E4%B8%8A%E6%89%8B%20EC ...
- PHP实现动态生成饼状图 (转载)
<?php //变量定义,画椭圆弧时的角度大小 define("ANGLELENGTH", 10); /** * 绘制图片 * @param $title 3D图的标题 * ...
- 自定义View饼状图的绘制
package com.loaderman.customviewdemo; import android.content.Context; import android.graphics.Canvas ...
- canvas图表详解系列(3):动态饼状图(原生Js仿echarts饼状图)
本章建议学习时间4小时 学习方式:详细阅读,并手动实现相关代码(如果没有canvas基础,需要先学习前面的canvas基础笔记) 学习目标:此教程将教会大家如何使用canvas绘制各种图表,详细分解步 ...
- iOS:使用贝塞尔曲线绘制图表(折线图、柱状图、饼状图)
1.介绍: UIBezierPath :画贝塞尔曲线的path类 UIBezierPath定义 : 贝赛尔曲线的每一个顶点都有两个控制点,用于控制在该顶点两侧的曲线的弧度. 曲线的定义有四个点:起始点 ...
- WPF 饼状图,柱形图,折线图 (3 饼状图)
网址:https://www.cnblogs.com/CSSZBB/p/12746214.html 饼状图相对来说复杂一些.因为需要计算很多坐标,线来看下这个列子. 圆首先想到Ellipse.但是El ...
随机推荐
- R语言-箱型图&热力图
1.箱型图 boxplot()函数 > metals<-read.csv("metals.csv",header=TRUE) #读取文件和列名 > boxplot ...
- FlannBasedMatcher 立体匹配
#include "opencv2/core/core.hpp" #include "opencv2/features2d/features2d.hpp" #i ...
- QUARTZ系列之一-基础概念(Scheduler/Job/JobDetail/Trigger)
摘抄自quartz官方文档: The key interfaces of the Quartz API are: Scheduler - the main API for interacting wi ...
- 初学c# -- 学习笔记(9) 关于SQL2008
在做一个局域网的类似网盘的学习练习,服务端差不多了,在改bug.用vlc的dll做的全格式视频.音频预览在线播放下载等等. 在做服务端也遇到了一些问题,走了好多弯路. 开始把上传的视频.音频.图像.文 ...
- Mac Eclipse 配置 SDK Manager Proxy (代理)
默认的下载地址非常慢,可以换成东软的代理. 顶部任务栏中选择SDK Manager -> 偏好设置 : 可以看到下载速度快了很多,出现类很多安装选项: 安装好后,在偏好设置窗口中,选择Clear ...
- 【python-dict】dict的使用及实现原理
以下内容是针对:python源码剖析中的第五章——python中Dict对象 的读书笔记(针对书中讲到的内容进行了自己的整理,并且针对部分内容根据自己的需求进行了扩展) 一.Dict的用法 Dict的 ...
- java通过年月得到该月每一天的日期
public static List<String> getDayByMonth(int yearParam,int monthParam){ List<String> lis ...
- vue-router 动态添加 路由
动态添加路由可以用了做权限管理.登录后服务器端返回权限菜单,前端动态添加路由 然后在设置菜单 1.vue-router 有方法router.addRoutes(routes) 动态添加更多的路由规则 ...
- ----一个roadmap----
在课上了解到了学web前端三个基础,HTML.CSS.JS 从HTML开始,逐步学习CSS.JS 大致写了一个roadmap(应该是roadmap喔 就是这样,以后可能会来更错或者更新 对没错我来更错 ...
- poj3304(是否存在一条直线与所有给出线段相交
题意:给出n条线段,问你是否存在一条直线让他与所有线段相交. 思路:枚举两条直线的起点和终点做一条直线,看他是否与所有线段相交. #include<cstdio> #include< ...