动态柱状图

www5net 2014-02-21 05:39:07
语言Csharp 软件 visual studio2010 数据库 sql server 2008 gid+绘图 完整代码 求教怎么做
...全文
205 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
www5net 2014-02-26
  • 打赏
  • 举报
回复
protected void Page_Load(object sender, EventArgs e) { this.CreateImage(); } private int Total() { SqlConnection Con = new SqlConnection(ConfigurationManager.AppSettings["ConSql1"]); Con.Open(); string cmdtxt1 = "select CONVERT(varchar(100), t1.FendDate, 23) as 结束日期,t2.Fqty as 额定产能,t2.Fuseqty as 已用产能 from t_planed_BOS t1,t_planedentry_BOS t2 where t1.FID =t2.FID and t1.FBillNo like '旬%' and t2.Fnumber='JG' and " + DropDownList1.SelectedValue.ToString().Trim() + " like '%" + TextBox1.Text.ToString().Trim() + "%'"; SqlDataAdapter dap = new SqlDataAdapter(cmdtxt1, Con); DataSet ds = new DataSet(); dap.Fill(ds); int P_Int_total = ds.Tables[0].Rows.Count;//访问人数统计 return P_Int_total; } private void CreateImage() { int height = 1000, width = 1000; Bitmap image = new Bitmap(width, height); //创建Graphics类对象 Graphics g = Graphics.FromImage(image); try { //清空图片背景色 g.Clear(Color.White); Font font = new Font("Arial", 9, FontStyle.Regular); Font font1 = new Font("宋体", 20, FontStyle.Bold); LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.BlueViolet, 1.2f, true); g.FillRectangle(Brushes.WhiteSmoke, 500, 500, width, height); // Brush brush1 = new SolidBrush(Color.Blue); g.DrawString("2014年各月份网站流量统计", font1, brush, new PointF(130, 30)); //画图片的边框线 g.DrawRectangle(new Pen(Color.Blue), 0, 0, image.Width - 1, image.Height - 1); Pen mypen = new Pen(brush, 1); //绘制线条 //绘制横向线条 int x = 100; for (int i = 0; i < 11; i++) { g.DrawLine(mypen, x, 80, x, 340); x = x + 40; } Pen mypen1 = new Pen(Color.Blue, 2); g.DrawLine(mypen1, x - 480, 80, x - 480, 340); //绘制纵向线条 int y = 106; for (int i = 0; i < 9; i++) { g.DrawLine(mypen, 60, y, 540, y); y = y + 26; } g.DrawLine(mypen1, 60, y, 540, y); //x轴 String[] n = {" 一月", " 二月", " 三月", " 四月", " 五月", " 六月", " 七月", " 八月", " 九月", " 十月", "十一月", "十二月","dddd"}; x = 62; for (int i = 0; i < 13; i++) { g.DrawString(n[i].ToString(), font, Brushes.Black, x, 348); //设置文字内容及输出位置 x = x + 40; } //y轴 String[] m = {"100%", " 90%", " 80%", " 70%", " 60%", " 50%", " 40%", " 30%", " 20%", " 10%", " 0%"}; y = 85; for (int i = 0; i < 11; i++) { g.DrawString(m[i].ToString(), font, Brushes.Black, 25, y); //设置文字内容及输出位置 y = y + 26; } int[] Count = new int[12]; string cmdtxt2 = ""; SqlConnection Con = new SqlConnection(ConfigurationManager.AppSettings["ConSql1"]); Con.Open(); SqlDataAdapter da; DataSet ds = new DataSet(); for (int i = 0; i < 12; i++) { cmdtxt2 = "select COUNT(10) AS count, Month( FendDate) AS month from t_planed_BOS where Year(FendDate)=2014 and Month(FendDate)=" + (i + 1) + "Group By Month(FendDate)"; da = new SqlDataAdapter(cmdtxt2, Con); da.Fill(ds, i.ToString()); if (ds.Tables[i].Rows.Count == 0) { Count[i] = 0; } else { Count[i] = Convert.ToInt32(ds.Tables[i].Rows[0][0].ToString()) * 100 / Total(); } } //显示柱状效果 x = 70; for (int i = 0; i < 12; i++) { SolidBrush mybrush = new SolidBrush(Color.Red); g.FillRectangle(mybrush, x, 340 - Count[i] * 26/5 , 20, Count[i] * 26/5); x = x + 40; } System.IO.MemoryStream ms = new System.IO.MemoryStream(); image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); Response.ClearContent(); Response.ContentType = "image/Jpeg"; Response.BinaryWrite(ms.ToArray()); } finally { g.Dispose(); image.Dispose(); }
www5net 2014-02-21
  • 打赏
  • 举报
回复
谁有现成代码 求发求指导
  • 打赏
  • 举报
回复
引用 2 楼 u013722684 的回复:
百度了太乱没时间研究
呵呵
www5net 2014-02-21
  • 打赏
  • 举报
回复
百度了太乱没时间研究
小贤820 2014-02-21
  • 打赏
  • 举报
回复
度娘哪里绝对有答案!!!

4,818

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 图表区
社区管理员
  • 图表区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧