<br /><br /><p></p><p><pre class="brush:csharp;">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.HtmlControls;using System.Drawing;using ZedGraph;using ZedGraph.Web;using System.Collections.Generic;namespace Zegraph{ /**/ /// <summary> /// 显示统计图形类型 /// </summary> public enum AnalyticsType { Line, //折线图 Bar, //柱状图 Pie //饼图 }; public partial class DrawGrap : System.Web.UI.UserControl { #region Private Attribute /**/ /// <summary> /// 默认颜色种类 /// </summary> private List<Color> defaultColors = new List<Color>(); /**/ /// <summary> /// 统计的个数 /// </summary> private int Count; #endregion #region Public Property /**/ /// <summary> /// 统计图的名称 /// </summary> public string Title; /**/ /// <summary> /// 横轴的名称(饼图不需要) /// </summary> public string XAxisTitle; /**/ /// <summary> /// 纵轴的名称(饼图不需要) /// </summary> public string YAxisTitle; /**/ /// <summary> /// 显示的曲线类型:Line,Bar,Pie /// </summary> public AnalyticsType Type; /**/ /// <summary> /// 折线图和柱状图的数据源 /// </summary> public List<PointPairList> DataSource = new List<PointPairList>(); /**/ /// <summary> /// 饼图的数据源 /// </summary> public List<double> ScaleData = new List<double>(); /**/ /// <summary> /// 各段数据的颜色 /// </summary> public List<Color> Colors = new List<Color>(); /**/ /// <summary> /// 各段数据的名称 /// </summary> public List<string> NameList = new List<string>(); /**/ /// <summary> /// 用于柱状图,每个圆柱体表示的含义 /// </summary> public List<string> LabelList = new List<string>(); #endregion protected void Page_Load(object sender, EventArgs e) { zedGraphControl.RenderGraph = new ZedGraph.Web.ZedGraphWebControlEventHandler(zedGraphControl_RenderGraph); } private void InitDefaultColors() { 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); } /**/ /// <summary> /// 如果属性为空则初始化属性数据 /// </summary> private void InitProperty() { 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) { Random r = new Random(); int tempIndex = 0; List<int> tempIndexList = new List<int>(); for (int i = 0; i < Count; i ) { tempIndex = r.Next(defaultColors.Count); if (tempIndexList.Contains(tempIndex)) { i--; } else { tempIndexList.Add(tempIndex); Colors.Add(defaultColors[tempIndex]); } } } if (NameList.Count == 0) { if (Type == AnalyticsType.Bar) { for (int i = 0; i < DataSource[0].Count; i ) { NameList.Add("第" i.ToString() "组"); } } else { for (int i = 0; i < Count; i ) { NameList.Add("第" i.ToString() "组"); } } } if (LabelList.Count == 0) { for (int i = 0; i < Count; i ) { LabelList.Add("含义" i.ToString()); } } } /**/ /// <summary> /// 画图51-a-s-px /// </summary> /// <param name="webObject"></param> /// <param name="g"></param> /// <param name="pane"></param> private void zedGraphControl_RenderGraph(ZedGraph.Web.ZedGraphWeb webObject, System.Drawing.Graphics g, ZedGraph.MasterPane pane) { InitProperty(); GraphPane myPane = pane[0]; myPane.Title.Text = Title; myPane.XAxis.Title.Text = XAxisTitle; myPane.YAxis.Title.Text = YAxisTitle; switch (Type) { case AnalyticsType.Line: DrawLine(myPane); break; case AnalyticsType.Bar: DrawBar(myPane); break; case AnalyticsType.Pie: DrawPie(myPane); break; default: break; } pane.AxisChange(g); } #region Draw /**/ /// <summary> /// 画折线图 /// </summary> /// <param name="graphPane"></param> private void DrawLine(GraphPane graphPane) { for (int i = 0; i < Count; i ) { graphPane.AddCurve(NameList[i], DataSource[i], Colors[i], SymbolType.None); } } /**/ /// <summary> /// 画柱状图 /// </summary> /// <param name="graphPane"></param> private void DrawBar(GraphPane graphPane) { for (int i = 0; i < Count; i ) { graphPane.AddBar(LabelList[i], DataSource[i], Colors[i]).Bar.Fill = new Fill(Colors[i], Color.White, Colors[i]); } graphPane.XAxis.MajorTic.IsBetweenLabels = true; string[] labels = NameList.ToArray(); graphPane.XAxis.Scale.TextLabels = labels; graphPane.XAxis.Type = AxisType.Text; graphPane.Fill = new Fill(Color.White, Color.FromArgb(200, 200, 255), 45.0f); graphPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f); } /**/ /// <summary> /// 画饼图 /// </summary> /// <param name="graphPane"></param> private void DrawPie(GraphPane graphPane) { graphPane.Fill = new Fill(Color.White, Color.Silver, 45.0f); graphPane.Legend.Position = LegendPos.Float; graphPane.Legend.Location = new Location(0.95f, 0.15f, CoordType.PaneFraction, AlignH.Right, AlignV.Top); graphPane.Legend.FontSpec.Size = 20f; graphPane.Legend.IsHStack = false; for (int i = 0; i < Count; i ) { graphPane.AddPieSlice(ScaleData[i], Colors[i], Color.White, 45f, 0, NameList[i]); } } /**/ /// <summary> /// 如果系统出错,显示错误信息 /// </summary> /// <param name="graphPane"></param> /// <param name="message"></param> private void DrawMessage(GraphPane graphPane, string message) { TextObj text = new TextObj(message, 200, 200); text.Text = message; graphPane.GraphObjList.Add(text); } #endregion }}</pre></p><p><br /></p>
下载表示业务统计的图表控件用户还喜欢
- 18480 文章数
- 500万+ 热度
作者专栏
编辑推荐
- 淡抹u2引擎,修复内容较多,物有所值
- 界域传说·经典巨作=传世单机(一键安装)
- 丸子版本(175个传世版本大集合)
- GS版本:神话公益服务端+客户端
- 图片放大工具(放大图片不模糊)
- 剪映无限制VIP版
- 传奇世界客户端下载器,史上最全传世客户端
- 传世GS20220920商业引擎注册+登录配置器 解压密码是1
- U2官方排行榜游戏网关 支持元神,支持传家宝
- GS开战传世客户端+服务端
- (淡漠夕阳)u2引擎合区工具
- 传世GS引擎消除“你的游戏客户端版本号过旧,请及时更新”提示
- 传世一机多区双线路配置器--免密码版本
- 传世凤凰登陆器劫持修复软件
- SQLite3 for Navicat
- 传奇世界npc对话框编辑工具
- 传世GS落霞铭文服务器端
- gs_20210409引擎包+注册机(无限制)
- 传奇世界NPC对话封包查看器[支持时长版和极速版]
- 彩虹引擎传世脚本编辑工具1.7版来了,支持函数脚本翻译
评论