.net c#动态生成随机饼状图报表

版权:原创 更新时间:1年以上
[该文章底部包含文件资源,可根据自己情况,决定是否下载资源使用,时间>金钱,如有需要,立即查看资源]

如果项目为了安全,不引入第三方dll,则可以使用Graphics自己画图,的情况下,
首先建一个实体:

        public class StatCount
        {
            /// <summary>
            /// 名称
            /// </summary>
            public string name { get; set; }
            /// <summary>
            /// 数量
            /// </summary>
            public int count { get; set; }
        }

从数据库中读取实体集合:

        public static Image Draw(List<StatCount> list, Image imgfont, int width = 500, int height = 500)
        {
            System.Drawing.Bitmap image = new System.Drawing.Bitmap(width, height);
            //创建Graphics类对象,用来画饼状图
            Graphics g = Graphics.FromImage(image);
            Pen p = new Pen(new SolidBrush(Color.Blue));
            Point p1 = new Point(0, 0);
            Size s = new Size(width, height);
            Rectangle trct = new Rectangle(p1, s);
            g.FillEllipse(new SolidBrush(Color.Red), trct);
            Font font = new Font("宋体", 10, FontStyle.Regular);
            int total = list.Sum((w) => { return w.count; });

            //写文字
            Graphics gfont = Graphics.FromImage(imgfont);
            int fontspan = 15;

            for (int i = 0; i < list.Count; i++)
            {
                //画大饼
                Color color = ColorIndex(i);
                float f = float.Parse(list[i].count.ToString()) / float.Parse(total.ToString());
                //写文字
                fontspan = fontspan + 15;
                //绘制小矩形
                gfont.FillRectangle(new SolidBrush(color), 0, fontspan, 20, 10);
                //写百分比文字
                gfont.DrawString(list[i].name + " " + FormatCentStr(total, list[i].count), font, new SolidBrush(Color.Blue), 30, fontspan);
            }
            return image;
        }

调用并测试画饼状图.

        public void DrawPie()
        {
            //年某商品走势
            List<GraPie.StatCount> list = new List<GraPie.StatCount>();
            int count = GraPie.Random().Next(2, 6);
            for (int i = 1; i <= count; i++)
            {
                list.Add(new GraPie.StatCount() { name = i.ToString() + "月", count = GraPie.Random(1, 1000) });
            }
            Image imgfont = new System.Drawing.Bitmap(zpictwo.Width, zpictwo.Height);
            zpic.BackgroundImage = GraPie.Draw(list, imgfont, zpic.Width, zpic.Height);
            zpictwo.BackgroundImage = imgfont;
        }

实现效果如下:

附件:下载该文件资源,减少时间成本(增值服务)
完整版权,经报备授权后可商用
上传者拥有该资源完整版权,下载既表明已授权您可以进行报备商用,无报备或者使用后报备,视为侵权,报备后使用,为合法有效使用,报备方式,下载后,在下载列表,点击报备,填写使用场景即可
File Source
.rar
237.14 KB
文件部分展示图(单击放大)
.net c#动态生成随机饼状图报表.net c#动态生成随机饼状图报表.net c#动态生成随机饼状图报表
留言
该资源可下载
File Source
.rar
237.14 KB
.net c#动态生成随机饼状图报表.net c#动态生成随机饼状图报表.net c#动态生成随机饼状图报表
最新结算
HTML5 3D效果网页视频背景代码
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
软件概要设计说明书Word下载
类型: .docx 金额: CNY 0.38¥ 状态: 待结算 详细>
软件概要设计说明书Word下载
类型: .docx 金额: CNY 3.02¥ 状态: 待结算 详细>
.net c#获取声卡信息,声卡数量
类型: .rar 金额: CNY 30.96¥ 状态: 待结算 详细>
.net c#获取声卡信息,声卡数量
类型: .rar 金额: CNY 3.87¥ 状态: 待结算 详细>
.net c#获取电脑的安装软件列表信息,包含名称和版本号
类型: .rar 金额: CNY 30.96¥ 状态: 待结算 详细>
.net c#获取电脑的安装软件列表信息,包含名称和版本号
类型: .rar 金额: CNY 3.87¥ 状态: 待结算 详细>
.net c#获取电脑显示适配器信息
类型: .rar 金额: CNY 30.96¥ 状态: 待结算 详细>
.net c#获取电脑的安装软件列表信息,包含名称和版本号
类型: .rar 金额: CNY 3.87¥ 状态: 待结算 详细>
.net c#获取电脑的安装软件列表信息,包含名称和版本号
类型: .rar 金额: CNY 30.96¥ 状态: 待结算 详细>
各执行环节公正透明,帮助企业完成从赛制策划、活动推广、评委评选到版权转让等系列工作,专业、高效、值得信赖。平均每场赛事可征集到数百至数千组源码作品
合作伙伴
联系我们
  • 邮箱:raozetian@hotmail.com
Copyright 2023-2024 eeigg.com·皖ICP备2024038726号-1
打赏文章