国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

餅形統計圖

2019-11-14 16:52:32
字體:
來源:轉載
供稿:網友

數據庫同 柱狀統計圖

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();    }}
View Code

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 四会市| 松阳县| 徐州市| 张掖市| 嘉峪关市| 石嘴山市| 江阴市| 金寨县| 安阳县| 博兴县| 盐津县| 平武县| 怀化市| 乡城县| 渑池县| 承德市| 金平| 浠水县| 穆棱市| 灵武市| 鄢陵县| 五华县| 当雄县| 万荣县| 仙游县| 九龙坡区| 禄劝| 垦利县| 开封县| 阳春市| 莆田市| 新疆| 柯坪县| 青海省| 丹阳市| 卓尼县| 宁安市| 安泽县| 吉林市| 虞城县| 阜宁县|