




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
1、用ZedGraph控件畫統(tǒng)計分析圖由于朋友需要把C1WebChart.替換掉,改用開源的ZedGraph控件.以下做一個示例,供大家參考:步驟如下:1、添加ZedGraph控件。如下圖: 2、添加到控制面版。如下圖:3、制作用戶控件。 a> 建立一個命名為: DrawGrap.ascx 用戶控件。 b> 通過控制面版,把ZedGraphWeb拖到默認(rèn)頁面。 如下圖: c> 生成代碼(DrawGrap.ascx)如下:
2、60; <% Control Language="C#" AutoEventWireup="true" CodeFile="DrawGrap.ascx.cs" Inherits="DrawGrap" %><% Register TagPrefix="zgw" Namespace="Zed
3、Graph.Web" Assembly="ZedGraph.Web" %><ZGW:ZEDGRAPHWEB id="zedGraphControl" runat="server" width="500" Height="375" RenderMode="ImageTag"/> d> 生成代碼(DrawGrap.ascx.cs)如下:
4、60;using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlCont
5、rols;using System.Drawing;using ZedGraph;using ZedGraph.Web;using System.Collections.Generic;/*/ <summary>/ 顯示統(tǒng)計圖形類型/ </summary>public enum AnalyticsType. Line, /折線圖 Bar,
6、0; /柱狀圖 Pie /餅圖;public partial class DrawGrap : System.Web.UI.UserControl. Private Attribute#region Private Attribute /*/ <summary>
7、60; / 默認(rèn)顏色種類 / </summary> private List<Color> defaultColors = new List<Color>(); /*/ <summary> / 統(tǒng)計的個數(shù) /&
8、#160;</summary> private int Count; #endregion Public Property#region Public Property /*/ <summary> / 統(tǒng)計圖的名稱 /
9、</summary> public string Title; /*/ <summary> / 橫軸的名稱(餅圖不需要) / </summary> public string XAxisTitle; /*/
10、<summary> / 縱軸的名稱(餅圖不需要) / </summary> public string YAxisTitle; /*/ <summary> / 顯示的曲線類型:Line,Bar,Pie / </s
11、ummary> public AnalyticsType Type; /*/ <summary> / 折線圖和柱狀圖的數(shù)據(jù)源 / </summary> public List<PointPairList> DataSource = new
12、 List<PointPairList>(); /*/ <summary> / 餅圖的數(shù)據(jù)源 / </summary> public List<double> ScaleData = new List<double>();
13、0;/*/ <summary> / 各段數(shù)據(jù)的顏色 / </summary> public List<Color> Colors = new List<Color>(); /*/ <summary> / 各段數(shù)
14、據(jù)的名稱 / </summary> public List<string> NameList = new List<string>(); /*/ <summary> / 用于柱狀圖,每個圓柱體表示的含義 / </summary
15、> public List<string> LabelList = new List<string>(); #endregion protected void Page_Load(object sender, EventArgs e) .
16、 zedGraphControl.RenderGraph += new ZedGraph.Web.ZedGraphWebControlEventHandler(zedGraphControl_RenderGraph); private void InitDefaultColors() .
17、160; defaultColors.Add(Color.Red); defaultColors.Add(Color.Green); defaultColors.Add(Color.Blue);
18、160; defaultColors.Add(Color.Yellow); defaultColors.Add(Color.YellowGreen); defaultColors.Add(Color.Brown
19、); defaultColors.Add(Color.Aqua); defaultColors.Add(Color.Cyan); defaultColors.Add(Colo
20、r.DarkSeaGreen); defaultColors.Add(Color.Indigo); /*/ <summary> / 如果屬性為
21、空則初始化屬性數(shù)據(jù) / </summary> private void InitProperty() . InitDefaultCol
22、ors(); if (string.IsNullOrEmpty(Title) . Title =
23、;"未命名統(tǒng)計圖" if (string.IsNullOrEmpty(XAxisTitle) .
24、; XAxisTitle = "橫軸" if (string.IsNullOrEmpty(YAxisTitle)
25、; . YAxisTitle = "縱軸"
26、60; if (Type = AnalyticsType.Pie) . Count = ScaleData.Count;
27、160; else .
28、60; Count = DataSource.Count; if (Colors.Count = 0 | Colors.Count != Count)
29、160; . Random r = new Random(); int tempIndex
30、;= 0; List<int> tempIndexList = new List<int>(); for (int i
31、0;= 0; i < Count; i+) . tempIndex = r.Next(defau
32、ltColors.Count); if (tempIndexList.Contains(tempIndex) .&
33、#160; i-;
34、0; else .
35、; tempIndexList.Add(tempIndex); Colors.Add(defaultColorstempIndex); &
36、#160; &
37、#160; if (NameList.Count = 0) . if (Type = AnalyticsType.Bar)
38、160; . for (int i = 0; i < DataSource0.Count; i+)
39、 . NameList.Add("第" + i.ToString() +&
40、#160;"組");
41、0; else . for (int i = 0; i
42、;< Count; i+) . NameList.
43、Add("第" + i.ToString() + "組");
44、160; if (LabelList.Count = 0) .
45、0; for (int i = 0; i < Count; i+) .
46、160; LabelList.Add("含義" + i.ToString();
47、160; /*/ <summary> / 畫圖 / </summary> / <param name="webObject">&l
48、t;/param> / <param name="g"></param> / <param name="pane"></param> private void ze
49、dGraphControl_RenderGraph(ZedGraph.Web.ZedGraphWeb webObject, System.Drawing.Graphics g, ZedGraph.MasterPane pane) . InitProperty(); &
50、#160; GraphPane myPane = pane0; myPane.Title.Text = Title; myPane.XAxis.Title.Text =
51、60;XAxisTitle; myPane.YAxis.Title.Text = YAxisTitle; /if (true) / &
52、#160; / DrawMessage(myPane, "yiafdhaskjhfasfksahfasdlhfaslf lasgfasglgsadi"); / pane.AxisChange(g);
53、; / return; / switch (Type)
54、160; . case AnalyticsType.Line: DrawLine(myPane);
55、60; break; case AnalyticsType.Bar:
56、; DrawBar(myPane); break; &
57、#160;case AnalyticsType.Pie: DrawPie(myPane); break;
58、; default: break;
59、60; pane.AxisChange(g); Draw#region Draw /*/ <summary>
60、; / 畫折線圖 / </summary> / <param name="graphPane"></param> private void DrawLine
61、(GraphPane graphPane) . for (int i = 0; i < Count; i+) . &
62、#160; graphPane.AddCurve(NameListi, DataSourcei, Colorsi, SymbolType.None); &
63、#160; /*/ <summary> / 畫柱狀圖 / </summary> / <param name="graphPane"></
64、param> private void DrawBar(GraphPane graphPane) . for (int i = 0; i < Count;
65、160;i+) . graphPane.AddBar(LabelListi, DataSourcei, Colorsi).Bar.Fill = new Fill(Colorsi, Color.White,
66、160;Colorsi); graphPane.XAxis.MajorTic.IsBetweenLabels = true; string l
67、abels = NameList.ToArray(); graphPane.XAxis.Scale.TextLabels = labels; graphPane.XAxis.Type = AxisType.Text;
68、160; graphPane.Fill = new Fill(Color.White, Color.FromArgb(200, 200, 255), 45.0f); graphPane.Chart.Fill = new Fill(Color.White,
69、;Color.LightGoldenrodYellow, 45.0f); /*/ <summary> / 畫餅圖 / </summary>
70、0; / <param name="graphPane"></param> private void DrawPie(GraphPane graphPane) . &
71、#160; graphPane.Fill = new Fill(Color.White, Color.Silver, 45.0f); graphPane.Legend.Position = LegendPos.Float;
72、 graphPane.Legend.Location = new Location(0.95f, 0.15f, CoordType.PaneFraction, AlignH.Right, AlignV.Top); graphPane.Legend.FontSpec.Size = 20f;
73、; graphPane.Legend.IsHStack = false; for (int i = 0; i < Count; i+)
74、160;. graphPane.AddPieSlice(ScaleDatai, Colorsi, Color.White, 45f, 0, NameListi);
75、60; /*/ <summary> / 如果系統(tǒng)出錯,顯示錯誤信息 / </summary> / <param
76、0;name="graphPane"></param> / <param name="message"></param> private void DrawMessage(GraphPane graphPane, string message)
77、160; . TextObj text = new TextObj(message, 200, 200); text.Text = message;
78、60; graphPane.GraphObjList.Add(text); #endregion e> 用戶控件制作完成。4、對控件的使用。 a> 創(chuàng)建測試頁面(DrawGrap.as
79、px) b> 把用戶控件DrawGrap.ascx 拖到默認(rèn)的測試頁面上(DrawGrap.aspx) c> 后臺代碼如下: using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebContr
80、ols;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;public partial class DrawGrap : System.Web.UI.Page. protected void Page_Load(object sender, EventArgs e) .
81、0; /柱狀圖 DrawBar(); /餅圖 /DrawPie(); /曲線圖
82、160; /DrawLine(); private void DrawBar() . DrawGrap1.Type = AnalyticsType.Bar; DrawGrap1.Title = &quo
83、t;用戶訪問柱狀圖" DrawGrap1.XAxisTitle = "月份" DrawGrap1.YAxisTitle = "用戶訪問數(shù)量" Random rand = new Rando
84、m(); for (int i = 0; i < 6; i+) . ZedGraph.PointPairList ppl = new ZedGr
85、aph.PointPairList(); for (int j = 0; j < 3; j+) .
86、 double x = rand.Next(10); double y = rand.NextDouble() * 1000; ppl.Add(x, y); DrawGrap1.DataSourc
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年工程專業(yè)管理試題及答案分析
- 學(xué)習(xí)項目風(fēng)險與經(jīng)濟效益的對比分析試題及答案
- 公共關(guān)系信息檢索技術(shù)試題及答案
- 2025年張掖市河西學(xué)院招聘考試筆試試題含答案
- 中級經(jīng)濟師考試的物價變動試題及答案
- 工程項目管理計劃編制試題及答案
- 2025年A特種設(shè)備相關(guān)管理考試模擬試題含答案
- 2025年市政工程給排水試題及答案
- 公共關(guān)系實務(wù)中的案例研究試題及答案
- 工程項目管理的知識轉(zhuǎn)化試題及答案
- 流動資金貸款額度測算表
- 2022中國流動人口發(fā)展報告
- 淡水養(yǎng)殖鱷魚課件
- 《無人機結(jié)構(gòu)與系統(tǒng)》第1章 無人機結(jié)構(gòu)與飛行原理
- 中國交通文化
- 外科技能操作考核評分表(縫合)
- 腸道病毒(共33張PPT)
- (完整word版)魚骨圖模板
- DB33T 2540-2022 生物安全實驗室管理評價規(guī)范
- 2023屆高三語文模擬試卷及參考答案2023年全國高考(北京卷)語文及試題解析
- 2022年衡陽市水務(wù)投資集團有限公司招聘筆試題庫及答案解析
評論
0/150
提交評論