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', ...
随机推荐
- git---如何在远程某个分支的基础上新建分支
问题场景 技术主管让你去再某个git分支上新建一个分支去做你的项目,那么如何在原远程分支的基础上新建自己的分支呢? 解决方法 按照以下命令敲即可 git branch newBranch //新建本地 ...
- Web自动化测试项目(四)测试报告
测试报告生成 使用HTMLTestRunner 生成测试报告 本文使用的 HTMLTestRunner 来源于github: https://github.com/githublitao/HTMLTe ...
- Paper慢慢读 - AB实验人群定向 Double Machine Learning
Hetergeneous Treatment Effect旨在量化实验对不同人群的差异影响,进而通过人群定向/数值策略的方式进行差异化实验,或者对实验进行调整.Double Machine Learn ...
- convertto-securestring结果 使用python解密
根据微软帮助文档,convertto-securestring有两种加密模式.如果在指定密码的情况下,则使用aes加密,否则使用windows dpapi加密.而且aes加密也没有指明iv值与加密模式 ...
- 删除我的电脑wps、百度网盘图标
删除我的电脑wps.百度网盘图标 删除下面子项 输入"计算机\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Expl ...
- Oracle操作语句--增加/删除
1.删除1980年雇员的雇员信息: delete from myemp where hiredate between to_date('1980-1-1','yyyy-mm-dd') and ...
- 关于在osgearth 中 出现 arial.ttf : file not handled 的问题
这是由于配置osg时 freetype 插件没有配置到位. 我个人的解决方法 打开CMAKE,点击advance,不勾选OSG_TEXT_USE_FONTCONFIG. 同时将freetype路径设置 ...
- Liunx 上安装java
linux系统的基本指令 http://www.cnblogs.com/sxdcgaq8080/p/7470796.html ===================================== ...
- Classmethod and Staticmethod - Python 类方法 和 静态方法
classmethod and staticmethod classmethod 的是一个参数是类对象 cls (本类,或者子类), 而不是实例对象 instance (普通方法). classmet ...
- Hapi+MySql项目实战自动化文档生成(四)
自动化生成swagger文档 使用hapi插件hapi-swagger,简单配置下插件,先修改下plugin_config.js文件: //plugin_config.js const Swagger ...