C#画图之饼图
public JsonResult DrawPie()
{
// 预置颜色
List<Color> colors = new List<Color>()
{
Color.FromArgb(,,),
Color.FromArgb(,,),
Color.FromArgb(,,),
Color.FromArgb(,,),
Color.FromArgb(,,),
Color.FromArgb(,,),
Color.FromArgb(,,),
Color.FromArgb(,,),
Color.FromArgb(,,)
}; #region 允许配置项 //定义宽高 只定义宽度即可
int height = , width = height; //边缘位置留白
int margin_top = ;
int margin_right = ;
int margin_bottom = ;
int margin_left = ; //文字大小,单位:px
int fontsize = ; // 扇区名称预留的位置 颜色框20,与文字间隙5,文字80,距离折线图10,需要包含边缘留白
int lineNameWidth = - margin_right; #endregion #region 数据 //最大数量/总数量
int totalCount = ; string[] pieNameData = new string[] { "第一个", "第二个", "第三个", "第四个", "第五个" };
int[] pieData = new int[] { , , , , }; totalCount = pieData.Sum(); #endregion //单位转换对象
Spire.Pdf.Graphics.PdfUnitConvertor unitCvtr = new Spire.Pdf.Graphics.PdfUnitConvertor(); //生成图像对象
Bitmap image = new Bitmap(width + margin_left + margin_right + lineNameWidth, height + margin_top + margin_bottom); //创建画布
Graphics g = Graphics.FromImage(image);
//消除锯齿
g.SmoothingMode = SmoothingMode.AntiAlias;
//质量
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.CompositingQuality = CompositingQuality.HighQuality; //黑色画笔--文字颜色
Brush blackBrush = new SolidBrush(Color.FromArgb(, , , ));
Pen blackPen = new Pen(blackBrush, ); //填充区域内容--背景
g.FillRectangle(Brushes.WhiteSmoke, , , width + margin_left + margin_right + lineNameWidth, height + margin_top + margin_bottom); //文字样式
Font font = new Font("宋体", unitCvtr.ConvertUnits(fontsize, Spire.Pdf.Graphics.PdfGraphicsUnit.Pixel, Spire.Pdf.Graphics.PdfGraphicsUnit.Point)); float tempAngle = ; for (int i = ; i < pieData.Length; i++)
{
Color tempColor = colors[i]; //文字内容
StringFormat format = new StringFormat();
//format.Alignment = StringAlignment.Far; //居中
//format.FormatFlags = StringFormatFlags.DirectionVertical; //画笔
SolidBrush brush = new SolidBrush(tempColor);
Pen pen = new Pen(brush, ); // 折线名称处理
// 颜色块
Rectangle rectangle = new Rectangle(margin_left + width + , margin_top + i * , , );
g.FillRectangle(brush, rectangle); // 文字
RectangleF txtRec = new RectangleF(margin_left + width + + , margin_top + i * + , , ); string txt = pieNameData[i].ToString() + "(" + Math.Round((pieData[i] / Convert.ToDouble(totalCount) * ), ).ToString() + "%)";
g.DrawString(txt, font, blackBrush, txtRec, format); /************************
* 开始画饼图
************************/
//饼图
int radius = (height > width ? width : height); Rectangle rec = new Rectangle(margin_left, margin_top, radius, radius); if (i < pieData.Length - )
{
float angle = Convert.ToInt32(pieData[i] / Convert.ToDouble(totalCount) * ); g.FillPie(brush, rec, tempAngle, angle); tempAngle += angle;
}
else
{
//防止计算误差导致不足360或者超过360
float angle = - tempAngle; g.FillPie(brush, rec, tempAngle, angle);
}
} string relativePath = @"\draw-image\" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpg";
string path = Server.MapPath(relativePath);
image.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg); //return relativePath;
return Json(relativePath, JsonRequestBehavior.AllowGet);
}
示例图

那种带把,把的末尾带文字的图,不会算啊,哪个会算的,有幸看到了能不能告诉我怎么算啊,跪谢!!!
带把的饼图(不会算的饼图)如下:

C#画图之饼图的更多相关文章
- 使用C#画图(饼图折线图)
public PlaceHolder PlaceHolder1; //显示图像的控件 各个图像的类别名称如下: PictureType 图形种类 5 chChartTypeBarCl ...
- python操作Excel、openpyxl 之图表,折线图、饼图、柱状图等
一.准备 需要模块: from openpyxl.workbook import Workbook from openpyxl.chart import Series,LineChart, Refer ...
- [C#]画图全攻略(饼图与柱状图)(转)
http://blog.chinaunix.net/uid-15481846-id-2769484.html 首先建立一个c#的类库. 打开vs.net,建立一个名为Insight_cs.WebC ...
- 画图前端:mermaid。时序图/类图/甘特图/流程图/状态图/饼图。类似工具:Typora
文档 https://mermaidjs.github.io/#/ cdn https://www.bootcdn.cn/mermaid/ 在线编辑 https://mermaidjs.github. ...
- (Vue中)cehart在同一个dom上画图图切换时饼图有折线图的坐标系
网上都是别人转载的,下面是转载的代码,在Vue中根本不适用 var echartrunningstate = null; if (echartrunningstate && echar ...
- python画图—黑板客老师课程学习
1.介绍 把每个图都看作一个对象,图中的每一个部分也是对象.——所有的一切都是对象. 工具——ipython notebook 是python里边用的最多的2D&3D的会图库,开源免费库,使用 ...
- html5实现饼图和线图-我们到底能走多远系列(34)
我们到底能走多远系列(34) 扯淡: 送给各位一段话: 人生是一个不断做加法的过程 从赤条条无牵无挂的来 到学会荣辱羞耻 礼仪规范 再到赚取世间的名声 财富 地位 ...
- (转)浅谈HTML5与css3画饼图!
神马系饼图? 饼图,大家都应该熟知,在统计数据对比方面,几乎处处用到.如cnzz的统计饼图 从饼图中,很形象地展示了访问者地区的分布,以扇形为块的方式拼成一个大圆. 都使用什么方法实现 目前众多站点制 ...
- 利用python进行折线图,直方图和饼图的绘制
我用10个国家某年的GDP来绘图,数据如下: labels = ['USA', 'China', 'India', 'Japan', 'Germany', 'Russia', 'Brazil', ...
随机推荐
- 我学React Native开发的经历(一) 第一周学习,环境搭建及demo1,一个导航跳转页面
大家好,这是跋涉者,wadereye,说来惭愧, 我是从2017年8月25日左右开始学习React Native的,因为时间不多, 在学习的过程中,感觉资料非常零散,要趟过的坑巨多,遇到的问题也非常多 ...
- linux启动Firefox报错,及解决方法
今天在安装Firefox时,出现如下错误 [root@localhost ~]# firefox XPCOMGlueLoad error for file /usr/lib64/firefox/lib ...
- Docker 容器数据 持久化(系统学习Docker05)
写在前面 本来是可以将数据存储在 容器内部 的.但是存在容器内部,一旦容器被删除掉或者容器毁坏(我亲身经历的痛,当时我们的大数据平台就是运行在docker容器内,有次停电后,不管怎样容器都起不来.以前 ...
- 懒人必备,IntelliJ IDEA中代码一键生成
之前有不少小伙伴问松哥微人事项目(https://github.com/lenve/vhr)使用的 MyBatis 逆向工程在哪里?其实旧版微人事当时没有使用逆向工程,是我自己手动敲出来的,当然手动敲 ...
- 用tensorflow搭建RNN(LSTM)进行MNIST 手写数字辨识
用tensorflow搭建RNN(LSTM)进行MNIST 手写数字辨识 循环神经网络RNN相比传统的神经网络在处理序列化数据时更有优势,因为RNN能够将加入上(下)文信息进行考虑.一个简单的RNN如 ...
- DOCKER 学习笔记9 Kubernetes (K8s) 生产级容器编排 上
前言 在上一节的学习中.我们已经可以通过最基本的 Docker Swarm 创建集群,然后在集群里面加入我们需要运行的任务 以及任务的数量 这样我们就创建了一个服务. 当然,这样的方式在我们本地虚拟机 ...
- Go语言实现:【剑指offer】数组中重复的数字
该题目来源于牛客网<剑指offer>专题. 在一个长度为n的数组里的所有数字都在0到n-1的范围内.数组中某些数字是重复的,但不知道有几个数字是重复的.也不知道每个数字重复几次.请找出数组 ...
- Windows搭建IIS服务器使用NATAPP实现内网穿透
目的:外网可以访问本地网页. 步骤: 一.实现内网访问 1.Win+Q搜索[控制面板],选择[程序],点击[启用或关闭Windows功能], 2.勾选[Internet Information Ser ...
- 使用 Visual Studio 2015 + Python3.6 + tensorflow 构建神经网络时报错:'utf-8' codec can't decode byte 0xcc in position 78: invalid continuation byte
使用 Visual Studio 2015 + Python3.6 + tensorflow 构建神经网络时报错:'utf-8' codec can't decode byte 0xcc in pos ...
- Git浅谈随笔之---如何工作
其他的版本控制工具我们常见的还有SVN,关于这两者的区别,我们不多谈,详见 Git 与 SVN 的区别 : Git是一种版本控制工具.用来记录文件内容的变化,备以后查阅某个版本的情况的系统:我们在Gi ...