资源预览内容
第1页 / 共13页
第2页 / 共13页
第3页 / 共13页
第4页 / 共13页
第5页 / 共13页
第6页 / 共13页
第7页 / 共13页
第8页 / 共13页
第9页 / 共13页
第10页 / 共13页
亲,该文档总共13页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
用ZedGraph控件画统计分析图由于朋友需要把C1WebChart.替换掉,改用开源的ZedGraph控件.以下做一个示例,供大家参考:步骤如下:1、添加ZedGraph控件。如下图: 2、添加到控制面版。如下图:3、制作用户控件。 a 建立一个命名为: DrawGrap.ascx 用户控件。 b 通过控制面版,把ZedGraphWeb拖到默认页面。 如下图: c 生成代码(DrawGrap.ascx)如下: d 生成代码(DrawGrap.ascx.cs)如下:usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Collections;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;usingSystem.Drawing;usingZedGraph;usingZedGraph.Web;usingSystem.Collections.Generic;/*/显示统计图形类型/publicenumAnalyticsType.Line,/折线图Bar,/柱状图Pie/饼图;publicpartialclassDrawGrap:System.Web.UI.UserControl.PrivateAttribute#regionPrivateAttribute/*/默认颜色种类/privateListdefaultColors=newList();/*/统计的个数/privateintCount;#endregionPublicProperty#regionPublicProperty/*/统计图的名称/publicstringTitle;/*/横轴的名称(饼图不需要)/publicstringXAxisTitle;/*/纵轴的名称(饼图不需要)/publicstringYAxisTitle;/*/显示的曲线类型:Line,Bar,Pie/publicAnalyticsTypeType;/*/折线图和柱状图的数据源/publicListDataSource=newList();/*/饼图的数据源/publicListScaleData=newList();/*/各段数据的颜色/publicListColors=newList();/*/各段数据的名称/publicListNameList=newList();/*/用于柱状图,每个圆柱体表示的含义/publicListLabelList=newList();#endregionprotectedvoidPage_Load(objectsender,EventArgse).zedGraphControl.RenderGraph+=newZedGraph.Web.ZedGraphWebControlEventHandler(zedGraphControl_RenderGraph);privatevoidInitDefaultColors().defaultColors.Add(Color.Red);defaultColors.Add(Color.Green);defaultColors.Add(Color.Blue);defaultColors.Add(Color.Yellow);defaultColors.Add(Color.YellowGreen);defaultColors.Add(Color.Brown);defaultColors.Add(Color.Aqua);defaultColors.Add(Color.Cyan);defaultColors.Add(Color.DarkSeaGreen);defaultColors.Add(Color.Indigo);/*/如果属性为空则初始化属性数据/privatevoidInitProperty().InitDefaultColors();if(string.IsNullOrEmpty(Title).Title=未命名统计图;if(string.IsNullOrEmpty(XAxisTitle).XAxisTitle=横轴;if(string.IsNullOrEmpty(YAxisTitle).YAxisTitle=纵轴;if(Type=AnalyticsType.Pie).Count=ScaleData.Count;else.Count=DataSource.Count;if(Colors.Count=0|Colors.Count!=Count).Randomr=newRandom();inttempIndex=0;ListtempIndexList=newList();for(inti=0;iCount;i+).tempIndex=r.Next(defaultColors.Count);if(tempIndexList.Contains(tempIndex).i-;else.tempIndexList.Add(tempIndex);Colors.Add(defaultColorstempIndex);if(NameList.Count=0).if(Type=AnalyticsType.Bar).for(inti=0;iDataSource0.Count;i+).NameList.Add(第+i.ToString()+组);else
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号