




版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
1、用ZedGraph控件畫統(tǒng)計分析圖由于朋友需要把C1WebChart.替換掉,改用開源的ZedGraph控件.以下做一個示例,供大家參考:步驟如下:1、添加ZedGraph控件。如下圖: 2、添加到控制面版。如下圖:3、制作用戶控件。 a> 建立一個命名為: DrawGrap.ascx 用戶控件。 b> 通過控制面版,把ZedGraphWeb拖到默認頁面。 如下圖: 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; / 默認顏色種類 / </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 拖到默認的測試頁面上(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)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年度婚姻介紹所涉外婚姻服務合同
- 二零二五餐飲業(yè)商鋪租賃合同附贈會員管理系統(tǒng)合作
- 2025年宜賓貨運從業(yè)資格考題
- 村支部書記發(fā)言稿
- 殘聯(lián)疫情發(fā)言稿
- 吉安市房屋租賃合同
- 藝術設計現(xiàn)代藝術理論題詳解
- 廚房發(fā)言稿200字
- 醫(yī)療設備采購合同協(xié)議書
- 軟件行業(yè)軟件開發(fā)作業(yè)指導書
- 中醫(yī)治療男科疾病的方法
- 2025年度花卉產(chǎn)業(yè)大數(shù)據(jù)服務平臺建設合同2篇
- 2025年度花卉產(chǎn)業(yè)大數(shù)據(jù)平臺建設合同3篇
- YY 0790-2024血液灌流設備
- 魚骨圖培訓課件
- 《基于STM32的公交車智能終端設計與實現(xiàn)》
- 護理禮儀與人文關懷
- 護-學-崗-簽-到-簿
- 運維服務體系建立實施方案(5篇)
- 路面基層(級配碎石)施工方案
- 四川政采評審專家入庫考試基礎題復習試題及答案(一)
評論
0/150
提交評論