WinForm绘制柱形图

一、绘制简单的柱形图

 private void button1_Click(object sender, EventArgs e){//创建画布Bitmap bitM = new Bitmap(this.panel1.Width, this.panel1.Height);Graphics g = Graphics.FromImage(bitM);g.Clear(Color.White);//清除背景色 并填充为白色//x y轴坐标 以及w  h绘制矩形的宽高int x, y, w, h;Random ran = new Random();for (int i = 0; i < 4; i++){//绘制名字g.DrawString("名字"+(i+1),new Font("宋体",8,FontStyle.Regular),new SolidBrush(Color.Black),76+40*i,this.panel1.Height-16);x = 78 + 40 * i;int num=ran.Next(40, 400); y = this.panel1.Height - 20-(num*20/100);w = 24;h = num * 20 / 100;g.FillRectangle(new SolidBrush(Color.FromArgb(60, 120, 80)), x, y, w, h);}this.panel1.BackgroundImage = bitM;}

二、绘制带有辅助线的柱形图 

 private void button1_Click(object sender, EventArgs e){int panelHeight=this.panel1.Height;int panelWidth=this.panel1.Width;//创建新的画布Bitmap bitM = new Bitmap(panelWidth,panelHeight);Graphics g = Graphics.FromImage(bitM);g.Clear(Color.White);Random ran = new Random();Pen RedPan = new Pen(new SolidBrush(Color.Red),2.0f);for (int i = 0; i < 12; i++){//绘制水平线g.DrawLine(RedPan, 50, panelHeight - 20 - i * 20, panelWidth - 40, panelHeight - 20 - i * 20);//绘制文字g.DrawString(i*100+"",new Font("宋体",10,FontStyle.Regular),new SolidBrush(Color.Black),20,panelHeight-27-i*20);}int x, y, w, h,ranNum;w = 24;for (int i = 0; i < 7; i++){//绘制垂直直线g.DrawLine(RedPan,50+40*i,panelHeight-20,50+40*i,20);//绘制名字g.DrawString("名字" + (i + 1), new Font("宋体", 8, FontStyle.Regular), new SolidBrush(Color.Black), 76 + 40 * i, panelHeight - 16);x = 78 + 40 * i;ranNum=ran.Next(50,250);y = panelHeight - 20 - ranNum;h = ranNum;g.FillRectangle(new SolidBrush(Color.FromArgb(60,130,80)),x,y,w,h);}g.DrawLine(RedPan, 50 + 40 * 7, panelHeight - 20, 50 + 40 * 7, 20);this.panel1.BackgroundImage = bitM;}

、绘制带有月份的柱形图 

 private void button1_Click(object sender, EventArgs e){int panelHeight = this.panel1.Height;int panelWidth = this.panel1.Width;//创建新的画布Bitmap bitM = new Bitmap(panelWidth, panelHeight);Graphics g = Graphics.FromImage(bitM);g.Clear(Color.White);//设置字体Font font = new Font("Arial",9,FontStyle.Regular);Font fontSong = new Font("宋体", 20, FontStyle.Regular);LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, bitM.Width, bitM.Height),Color.Blue,Color.Green,1.2f,true);g.FillRectangle(Brushes.WhiteSmoke, 0, 0, panelWidth, panelHeight);Brush brush1 = new SolidBrush(Color.Blue);g.DrawString("2018XX走势", fontSong, brush1, new PointF(180, 30));//画图片的边框线g.DrawRectangle(new Pen(Color.Blue),0,0,panelWidth-4,panelHeight-4);Pen mypen = new Pen(brush,1f);//绘制纵向线条int x = 50;for (int i = 0; i < 13; i++){g.DrawLine(mypen,x,75,x,307);x += 40;}// 绘制横向线条int y = 74;for (int i = 0; i < 10; i++){g.DrawLine(mypen, 50, y, 530, y);y += 26;}//绘制X轴月份string[] strX = { "一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月" };x = 45;for (int i = 0; i < strX.Length; i++){g.DrawString(strX[i].ToString(),font,Brushes.Red,x,panelHeight-30);x += 40;}//绘制Y轴数量string[] StrY = { "0", "100", "200", "300", "400", "500", "600", "700", "800" };y = 78;for (int i = 0; i < StrY.Length; i++){g.DrawString(StrY[StrY.Length-i-1].ToString(), font, Brushes.Red, 25, y);y += 26;}//填充数据Random ran = new Random();x = 55;y = 220;int  h=0;for (int i = 0; i < strX.Length; i++){int ranNum=ran.Next(0,800);SolidBrush sb = new SolidBrush(Color.FromArgb(150,0,0));h = ranNum /4;g.FillRectangle(sb, x +i * 30, y-h+88, 30, h);x +=10;}this.panel1.BackgroundImage = bitM;}

posted on 2018-02-03 16:25 adminyu 阅读(...) 评论(...) 编辑 收藏

转载于:https://www.cnblogs.com/zyadmin/p/8409813.html

WinForm绘制柱形图相关推荐

  1. WinForm绘制带有升序、降序的柱形图

    WinForm绘制带有升序.降序的柱形图 private void HuiZhiTu( string strPaiXu){//初始数据int[] nums = { 150, 89, 200, 60, ...

  2. 数据库PHP绘制柱形图,php使用Jpgraph绘制柱形图的方法

    本文实例讲述了php使用Jpgraph绘制柱形图的方法.分享给大家供大家参考.具体实现方法如下: include ("src/jpgraph.php"); include (&qu ...

  3. iOS使用Charts框架绘制—柱形图

    首先看一下最终要实现的效果: 最终效果 一.初始化barChartView 绘制柱形图需要用到BarChartView这个类,下面是初始化代码: self.barChartView = [[BarCh ...

  4. java怎么用柱形图_java绘制柱形图

    使用模拟数据绘制一个柱形统计图:重写paint()方法. 代码: import java.awt.Color; import java.awt.Graphics; import java.awt.Gr ...

  5. WinForm绘制直线、曲线、矩形、椭圆、圆弧

    WinForm绘制直线.曲线.矩形.椭圆.圆弧 新建一个窗体.添加六个按钮,插入下面的代码.得到上图. private void button1_Click(object sender, EventA ...

  6. python做excel表格柱状图_Python Excel 绘制柱形图

    原博文 2019-11-19 22:07 − 本文主要讲述如何使用Python操作Excel绘制柱形图. 相关代码请参考 https://github.com/RustFisher/python-pl ...

  7. 用Java绘制柱形图_Java使用JFreeChart绘制柱形图

    JFreeChart是JAVA平台上的一个开放的图表绘制类库.它完全使用JAVA语言编写,是为applications, applets, servlets 以及JSP等使用所设计.JFreeChar ...

  8. python画柱状图-Python Excel 绘制柱形图

    本文主要讲述如何使用Python操作Excel绘制柱形图. 开发工具,环境 PyCharm Python3 Office Excel 前面我们已经创建好了一张Excel表. 现在我们要根据已有的数据, ...

  9. python中绘制柱形图、饼形图等

    最近因工作原因,使用python的绘图功能,绘制生产的直通率数据,贴上代码,便于以后需要时摘用 1.选择报表所在路径: def ReportLocationpushButtonClick(self): ...

最新文章

  1. linux怎么获取当前路径,linux 下获取当前工作路径的实例
  2. golang mysql大量写入_Golang 实现分片读取http超大文件流和并发控制
  3. c++中的enum类型
  4. Spine学习六 - 碰撞检测
  5. 网络资产管理系统_RFID固定资产管理系统_企业资产管理方案
  6. 【转载】利用scipy.misc等库对jpg以及png等图像数据预处理(用于深度学习喂数据)...
  7. 介绍OpenHub框架
  8. SaaS 客户生命周期(逐字稿+PPT)
  9. 设置mysql从库延迟主库一小时
  10. css3实现翻转效果,css3 实现3D翻转效果
  11. CAD转KML乱码处理
  12. B1105 Spiral Matrix (画图)
  13. 中学计算机课小课题,【信息技术课题研究方案】 信息技术小课题研究题目大全_信息技术课题研究题目_信息技术课题研究_东城教研...
  14. 在“动物杂交:新视野”中快速赚钱的9种方法
  15. 欧拉回路(简单判断是否有欧拉回路存在)
  16. R语言使用报错及处理总结(不断更新)
  17. unity3d实现简单的打飞碟游戏
  18. 最新饿了么、美团、大众点评技术面面试难点整理,看完长点心
  19. HDU 4262 Juggler (模拟+线段树优化)
  20. bios设置raid启动模式Linux,华硕主板BIOS里哪项是开启RAID方式?

热门文章

  1. 检测是否是手机访问接口
  2. 共享上网 路由器设置图解
  3. 【计算机网络】详解HttpURLConnection
  4. 一、 promise
  5. PHP学习笔记六【方法-递归】
  6. [转载]Memcache内存临界测试
  7. 物联网在智慧仓库的价值体现
  8. react的一些思考
  9. 专访.NET平台上类RoR开源项目Castle[转载]
  10. 互联网协议入门 : 用户 ------ 底层