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', ...
随机推荐
- python之路:day2
本节内容 列表.元组操作 字符串操作 字典操作 集合操作 文件操作 字符编码与转码 1. 列表.元组操作 列表是我们最以后最常用的数据类型之一,通过列表可以对数据实现最方便的存储.修改等操作 定义列表 ...
- 双括号(()),shell与C++的桥梁
使用语法: ((表达式))用来扩展Shell中的算术运算,以及赋值运算,扩展for,while,if条件测试运算. 注意点: 1.在双括号结构中,所有的表达式可以像c语言一样,如a++,b-- 2.在 ...
- .NET异步编程之APM模式
目录 1.AMP模式简介 2.使用BeginInvoke实现异步委托 3.原始线程怎么知道新线程已经运行完毕 4.使用AsyncCallback委托实现回调模式 5.源代码下载 shanzm-2020 ...
- LUA学习笔记(第18-20章)
数学库 print(math.pi)-->π print(math.huge)-->Lua中表示的最大数字 --[[ 3.1415926535898 1.#INF ]] print(mat ...
- python UnicodeDecodeError: 'gbk' codec can't decode byte 0x99 in position 87: illegal multibyte sequence异常解决
我们处理文本文件时,经常会遇到这样的报错: UnicodeDecodeError: 'gbk' codec can't decode byte 0x99 in position 87: illegal ...
- tornado自定义分页扩展
一.分页扩展类 #! /usr/bin/env python # -*- coding:utf-8 -*- # __author__ = "TKQ" class Paginatio ...
- POJ_3663_贪心
题目描述: 给你一堆数和一个限定的空间大小,要求求出两个数的和小于等于空间大小的对数. 思路: 贪心,先给一堆数从大到小排序. 第一个数取数组第一个,第二个数从第二个开始依次往后取,只要某个第二个数满 ...
- 《Python学习手册 第五版》 -第9章 元组、文件与其他核心类型
本章的主要内容是介绍了元组和文件的使用,同时作为介绍数据类型的最后一个章节,本章也总结和复习了前面所介绍的核心数据类型,总结的部分在此不多介绍,因为前面章节都有,在此就重点介绍以下两点内容 1.元组 ...
- 动手学习pytorch——(2)softmax和分类模型
内容太多,捡重要的讲. 在分类问题中,通常用离散的数值表示类别,这里存在两个问题.1.输出值的范围不确定,很难判断值的意义.2.真实标签是离散值,这些离散值与不确定的范围的输出值之间的误差难以衡量. ...
- python学习(8)实例:写一个简单商城购物车的代码
要求: 1.写一段商城程购物车序的代码2.用列表把商城的商品清单存储下来,存到列表 shopping_mail3.购物车的列表为shopping_cart4.用户首先输入工资金额,判断输入为数字5.用 ...