饼形统计图
2018-06-18 03:42:04来源:未知 阅读 ()
数据库同 柱状统计图
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Configuration; using System.Drawing; using System.Data; using System.Collections; using System.IO; public partial class CakeImage : System.Web.UI.Page { public string connStr = ConfigurationManager.ConnectionStrings["VisitCountConnectionString"].ToString(); protected void Page_Load(object sender, EventArgs e) { DrawLinearGradient(); } //访问人数统计 public int Total() { int result = -1; string sql = "select count(1) from VisiteCount"; SqlConnection conn = new SqlConnection(connStr); conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); result = Convert.ToInt32(cmd.ExecuteScalar()); cmd.Dispose(); conn.Close(); return result; } //柱形图 public void DrawLinearGradient() { int[] count = new int[12]; string sql = ""; SqlConnection conn = new SqlConnection(connStr); conn.Open(); SqlDataAdapter da; DataSet ds = new DataSet(); for (int i = 0; i < 12; i++) { sql = @"select count(1) as count,Month(loginTime) as month from VisiteCount where YEAR(loginTime)=2013 and MONTH(loginTime)=" + (i + 1) + " group by MONTH(loginTime)"; da = new SqlDataAdapter(sql, conn); 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(); count[i] = Convert.ToInt32(ds.Tables[i].Rows[0][0].ToString()); } } //设置字体 Font fontlegend = new Font("verdana",9); Font fonttitle = new Font("verdana", 10, FontStyle.Bold); //设置背景宽度 int width = 230; int bufferspace = 15; int lengendheight = fontlegend.Height * 13 + bufferspace;//饼图下方分类表表高度 int titleheight = fonttitle.Height+bufferspace;//标题栏高度 int height = width+lengendheight+titleheight+bufferspace;//白色背景的高度 int pieheight = width;//饼图的高度 Rectangle pierect = new Rectangle(0, titleheight, width, pieheight); //加随机色 ArrayList colors = new ArrayList(); Random rnd = new Random(); for (int i = 0; i < 12; i++) { colors.Add(new SolidBrush(Color.FromArgb(rnd.Next(255),rnd.Next(255),rnd.Next(255)))); } //创建一个bitmap Bitmap objimage = new Bitmap(width,height); Graphics objg = Graphics.FromImage(objimage); objg.FillRectangle(Brushes.White, 0, 0, width, height); //画一个亮色背景 objg.FillRectangle(new SolidBrush(Color.Beige),pierect); //显示标题 objg.DrawString("2013网站浏览每月比例调查", fonttitle, Brushes.Black, new PointF(32,12)); //画饼图 float currentnum = 0.0f; for (int i = 0; i < 12; i++) { objg.FillPie((SolidBrush)colors[i], pierect, currentnum, Convert.ToSingle(count[i]) / Total() * 360); currentnum+=Convert.ToSingle(count[i]) / Total() * 360; } objg.DrawRectangle(new Pen(Color.Blue, 2), 0, height - lengendheight, width, lengendheight); string[] n = {"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"}; for (int i = 0; i < 12; i++) { objg.FillRectangle((SolidBrush)colors[i], 5, height - lengendheight+fontlegend.Height*i+5,10,10); string dble = (Convert.ToDouble(count[i]) / Total() * 100).ToString().Substring(0, 4)+"%"; objg.DrawString(n[i] + "----" + dble, fontlegend, Brushes.Black,20, height - lengendheight+fontlegend.Height*i+1); } objg.DrawString("2013网络浏览总数:" + Total() + "次", fontlegend, Brushes.Black, 5, height - fontlegend.Height); Response.ContentType="image/Jpeg"; objimage.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg); objg.Dispose(); objimage.Dispose(); } }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- 统计字符的个数,能够组成几个acmicpc 2019-10-16
- 长乐国庆集训Day1 2019-10-08
- C/C++应用程序内存泄漏检查统计方案 2019-08-16
- Luogu P2590 [ZJOI2008]树的统计 2019-02-20
- PAT (Basic Level) Practice 1021 个位数统计 2018-08-26
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash