C#绘制柱形图
柱形图数据
通过 panel 绘制柱形图
private void ShowPic() { Conn(); //打开数据库连接 using (cmd = new SqlCommand("SELECT TOP 3 * FROM tb_Rectangle order by t_Num desc", con)) { SqlDataReader dr = cmd.ExecuteReader(); //创建SqlDataReader对象 Bitmap bitM = new Bitmap(this.panel1.Width, this.panel1.Height); //创建画布 Graphics g = Graphics.FromImage(bitM); //创建Graphics对象 g.Clear(Color.White); //设置画布背景 for (int j = 0; j < 4; j++) //开始读取数据库中的数据并绘图 { if (dr.Read()) //读取记录集 { int x, y, w, h; //声明变量存储坐标和大小 g.DrawString(dr[0].ToString(), new Font("宋体", 8, FontStyle.Regular), new SolidBrush(Color.Black), 76 + 40 * j, this.panel1.Height - 16); //绘制文字 x = 78 + 40 * j; //x坐标 y = this.panel1.Height - 20 - Convert.ToInt32((Convert.ToDouble(Convert.ToDouble(dr[1].ToString()) * 20 / 100))); //y坐标 w = 24; //宽 h = Convert.ToInt32(Convert.ToDouble(dr[1].ToString()) * 20 / 100);//高 g.FillRectangle(new SolidBrush(Color.FromArgb(56, 129, 78)), x, y, w, h);//开始绘制柱形图 } } this.panel1.BackgroundImage = bitM; //显示绘制的柱形图 } }
付费内容,请联系本人QQ:1002453261
本文来自博客园,作者:明志德道,转载请注明原文链接:https://www.cnblogs.com/for-easy-fast/p/16485416.html
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析