用Graphics绘制柱状图
来源:互联网 发布:双卡手机都是4g网络吗 编辑:程序博客网 时间:2024/04/28 14:32
HuoClassLibrary.DbHelperOleDb db = new HuoClassLibrary.DbHelperOleDb("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + System.Web.HttpContext.Current.Server.MapPath("/db/jbh_newyear.mdb")); public string[] X = new string[7]; public string[] Y = new string[7]; public void ProcessRequest(HttpContext context) { GetTime(); Bitmap bm = new Bitmap(700, 350); Graphics g = Graphics.FromImage(bm); g.Clear(Color.Snow); g.DrawString(" 杭州骏宝行抽奖码报名详情", new Font("黑体", 16), Brushes.Black, new Point(220, 15)); Point myRec = new Point(600,30); Point myDec = new Point(835, 700); g.DrawString("单位:个", new Font("宋体", 11), Brushes.Black, new Point(615, 20)); for (int i = 0; i < X.Length; i++) { if (Y[i] != null) { if (Y[i] != "0") { //绘制小方块 g.DrawRectangle(Pens.Black, myRec.X, myRec.Y + 10, 20, 10); //填充小方块 g.FillRectangle(new SolidBrush(GetColor(i)), myRec.X, myRec.Y + 10, 20, 10); if (X[i] != null) { g.DrawString(X[i].ToString(), new Font("宋体", 9), Brushes.Black, new Point(623, myRec.Y + 10)); } } } myDec.Y += 15; myRec.Y += 15; } int iBarWidth = 70; int scale = 1; for (int i = 0; i <Y.Length; i++) { if (Y[i] != null) { if (Y[i] != "0") { int width=(Convert.ToInt32(Y[i].ToString()) * scale) / 5 + 5; int y = 350 - (Convert.ToInt32(Y[i].ToString()) * scale) /5; g.DrawRectangle(Pens.Black, (i * iBarWidth) + 50, y, 20, width); //绘制Bar图 g.FillRectangle(new SolidBrush(GetColor(i)), (i * iBarWidth) + 50, y, 20, width); //以指定的色彩填充Bar图 g.DrawString(Y[i].ToString(), new Font("宋体", 9), Brushes.Black, (i * iBarWidth) + 50, y-25); } } } Pen p = new Pen(Color.Black, 2); g.DrawRectangle(Pens.Black, 1, 1, 698, 348); bm.Save(context.Response.OutputStream, ImageFormat.Gif); } public Color GetColor(int i) { if (i % 7 == 0) { return Color.Red; } if (i % 7 == 1) { return Color.Blue; } if (i % 7 == 2) { return Color.DarkSlateGray; } if (i % 7 == 3) { return Color.Gray; } if (i % 7 == 4) { return Color.Green; } if (i % 7 == 5) { return Color.Pink; } if (i % 7 == 6) { return Color.PapayaWhip; } else { return Color.Gold; } } //获取时间列表 public void GetTime() { DateTime time = Convert.ToDateTime("2015/2/1"); DateTime endtime = Convert.ToDateTime("2015/2/7"); int i = 0; while (time <= endtime) { X[i] = time.ToString("yyyy/M/d"); string sql = "select * from active_play where dttime like '%2015/2/" + (i + 1) + "%' and tid>1"; var dt = db.ExecuteQuery(sql); Y[i] = dt.Rows.Count.ToString(); i++; time = time.AddDays(1); } } public bool IsReusable { get { return false; } }
0 0
- 用Graphics绘制柱状图
- 用Qt绘制柱状图
- C#用Graphics绘制雪人
- 用graphics绘制验证码
- 柱状图绘制
- Asp.net 用 Graphics 统计图(柱状图, 折线图, 扇形图)
- 在C#用Graphics绘制图形(雪人)
- 绘制柱状图的类
- OWC11绘制柱状图
- ExtJs 绘制柱状图
- C#绘制柱状图
- .net绘制柱状图
- php GD绘制柱状图
- highcharts 绘制 柱状图
- android 绘制柱状图等
- gnuplot 绘制 柱状图
- android Achartengine绘制柱状图
- Php绘制柱状图
- 集合架构——简单数据结构
- BMITime_2_2:BMI指数(即身体质量指数,称简体质指数又称体重,英文为Body Mass Index,简称BMI)
- [objc.io]从像素到屏幕显示思维导图
- Java程序员到架构师的推荐阅读书籍
- Python内置函数大全
- 用Graphics绘制柱状图
- Hello World!
- Android fragment 使用replace并保存状态
- struts2中的addActionError 、addFieldError、addActionMessage的方法
- 树莓派-添加国内软件源
- Flatten Binary Tree to Linked List
- java中读取properties中的值
- IPSec VPN与SSL VPN 比较(转)
- SEO实战:解读站内优化的秘密