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

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

折線統計圖

2019-11-15 02:27:40
字體:
來源:轉載
供稿:網友

折線統計圖

數據庫代碼同 柱狀統計圖。

Default.aspx頁面代碼

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.IO;using System.Drawing.Drawing2D;using System.Data;public partial class LineTJImage : 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 width = 600, height = 400;        Bitmap image = new Bitmap(width,height);        Graphics g = Graphics.FromImage(image);        g.Clear(Color.White);        //畫矩形        g.FillRectangle(Brushes.WhiteSmoke, new Rectangle(0, 0, width, height));        LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0,0,width,height),Color.Blue,Color.BlueViolet,1.2f,true);        Font font = new Font("Arial",9,FontStyle.Regular);        Font font1 = new Font("宋體",20,FontStyle.Bold);        //寫標題        g.DrawString("2013網站瀏覽次數統計",font1,brush,new PointF(120,30));        Pen pen = new Pen(Color.Blue);        Pen pen1 = new Pen(Color.Blue,2);        //畫邊框        g.DrawRectangle(pen, 0, 0, width-1, height - 1);        //設定橫向起始        int x = 100;        for (int i = 0; i < 11; i++)        {            g.DrawLine(pen, x, 80, x, 340);            x += 40;        }        //畫y軸線        int y = 106;        for (int i = 0; i <9; i++)        {            g.DrawLine(pen, 60, y,540,y);            y += 26;        }        g.DrawLine(pen1, 60, y, 540, y);        //畫X軸線條        g.DrawLine(pen1,x-480,80,x-480,340);        //X軸        string[] n = {"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};        x = 62;        for (int i = 0; i < 12; i++)        {            g.DrawString(n[i],font,Brushes.Black,new PointF(x,348));            x += 40;        }        g.DrawString("人/月", new Font("宋體",10,FontStyle.Italic), Brushes.Black, new PointF(35, 348));        //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 + 25;        }        //將檢索出的數據按一定比例繪制到圖像中        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());            }        }        x = 70;        Point[] points = new Point[12];        for (int i = 0; i < 12; i++)        {            //g.DrawLine(pen            //g.DrawLine(pen, x, 340 - count[i] * 26 / 10, 20, count[i] * 26 / 10);            points[i] = new Point(x, 340 - count[i] * 26 / 10);            x += 40;        }        g.DrawLines(pen,points);        MemoryStream ms = new MemoryStream();        image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);        Response.ClearContent();        Response.ContentType = "image/Jpeg";        Response.BinaryWrite(ms.ToArray());    }}
View Code


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 平塘县| 盐边县| 建德市| 股票| 永安市| 淮安市| 天津市| 嘉禾县| 尖扎县| 长宁区| 故城县| 宁德市| 阳西县| 蓬溪县| 宝应县| 宁武县| 巴林左旗| 抚顺市| 铁岭县| 巫山县| 邵阳县| 泸州市| 长乐市| 岚皋县| 临海市| 武定县| 肥城市| 定安县| 普格县| 府谷县| 凤翔县| 石嘴山市| 松江区| 新竹县| 保山市| 安丘市| 左贡县| 万全县| 招远市| 石首市| 连州市|