




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、用ZedGraph控件画统计分析图由于朋友需要把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>/ 显示统计图形类型/ </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> / 统计的个数 /&
8、#160;</summary> private int Count; #endregion Public Property#region Public Property /*/ <summary> / 统计图的名称 /
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> / 折线图和柱状图的数据源 / </summary> public List<PointPairList> DataSource = new
12、 List<PointPairList>(); /*/ <summary> / 饼图的数据源 / </summary> public List<double> ScaleData = new List<double>();
13、0;/*/ <summary> / 各段数据的颜色 / </summary> public List<Color> Colors = new List<Color>(); /*/ <summary> / 各段数
14、据的名称 / </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、空则初始化属性数据 / </summary> private void InitProperty() . InitDefaultCol
22、ors(); if (string.IsNullOrEmpty(Title) . Title =
23、;"未命名统计图" 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> / 如果系统出错,显示错误信息 / </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> 创建测试页面(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 = "用户访问数量" 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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 工业互联网平台联邦学习隐私保护在网络安全领域的应用与防护策略
- 2025年高效复习工程项目管理试题及答案
- K2教育2025年STEM课程实施与教育创新人才培养报告
- 工程经济外部投资者关系试题及答案
- 公文写作结构与实践试题及答案
- 精密装备及关键零部件生产建设项目实施方案(参考模板)
- 行政管理实践中的应用试题及答案
- 行政管理与市政学的价值体系试题及答案
- 公共关系活动的评估标准与方法试题及答案
- 公共政策实施的最佳实践试题及答案
- 硬件安全与防护概述
- 续签租房合同正式版模板
- 职工生育保险待遇申报表
- 10千伏及以下可研深度规定
- 加快建设教育强国专题课件ppt
- 燃气公司生产运营管理制度
- 新媒体数据分析高职PPT完整全套教学课件
- 肺功能检查考试试题
- 轻度运动损伤的自我处理
- 学管师薪资体系
- 尾矿库名词解释
评论
0/150
提交评论