zedgraph画曲线柱状图

上传人:第*** 文档编号:32819515 上传时间:2018-02-12 格式:DOC 页数:13 大小:46.50KB
返回 下载 相关 举报
zedgraph画曲线柱状图_第1页
第1页 / 共13页
zedgraph画曲线柱状图_第2页
第2页 / 共13页
zedgraph画曲线柱状图_第3页
第3页 / 共13页
zedgraph画曲线柱状图_第4页
第4页 / 共13页
zedgraph画曲线柱状图_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《zedgraph画曲线柱状图》由会员分享,可在线阅读,更多相关《zedgraph画曲线柱状图(13页珍藏版)》请在金锄头文库上搜索。

1、使用 ZedGraph 画曲线柱状图刚接触到 ZedGraph,到网上搜素到的方法基本上都是使用临时文件来存储图片,然后再显示,但是临时图片太多的话会占用大量的空间。很不划算。最后看到有人说把RenderMode=RawImage就可以了 ,但是会出现乱码。如何解决呢?下面是我的方法。新建一个目录,命名为 bin,把文件 ZedGraph.Web.dll,ZedGraph.dll 拷到 bin 目录下面。建立文件 tuppian.aspx。其内容为:tuppian.aspx.cs 为:using System; using System.Data; using System.Configura

2、tion; 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; public partial class tuppian : Syst

3、em.Web.UI.Page DarwGrapClass dg = new DarwGrapClass(); protected void Page_Load(object sender, EventArgs e) protected override void OnInit(EventArgs e) InitializeComponent(); base.OnInit(e); private void InitializeComponent() string id = Request.QueryStringid; switch (id) case 1: DrawLine(); break;

4、case 2: DrawPie(); break; default: DrawBar(); break; private void DrawBar() dg.Type = AnalyticsType.Bar; dg.Title = 用户访问柱状图; dg.XAxisTitle = 月份; dg.YAxisTitle = 用户访问数量; Random rand = new Random(); string aa = 企业 1, 企业 2, 企业 3 ; for (int i = 0; i defaultColors = new List(); /*/ / / 统计的个数 / private in

5、t Count; #endregion /Public Property; #region Public Property /*/ / / 统计图的名称 / public string Title; /*/ / / 横轴的名称(饼图不需要) / public string XAxisTitle; /*/ / / 纵轴的名称(饼图不需要) / public string YAxisTitle; /*/ / / 显示的曲线类型:Line,Bar,Pie / public AnalyticsType Type; /*/ / / 折线图和柱状图的数据源 / public List DataSource

6、 = new List(); /*/ / / 饼图的数据源 / public List ScaleData = new List(); /*/ / / 各段数据的颜色 / public List Colors = new List(); /*/ / / 各段数据的名称 / public List NameList = new List(); /*/ / / 用于柱状图,每个圆柱体表示的含义 / public List LabelList = new List(); public double y_step; public double x_step; #endregion public voi

7、d DarwGrap(ZedGraphWeb ZedGraph) ZedGraph.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); defaul

8、tColors.Add(Color.YellowGreen); defaultColors.Add(Color.Brown); defaultColors.Add(Color.Aqua); defaultColors.Add(Color.Cyan); defaultColors.Add(Color.DarkSeaGreen); defaultColors.Add(Color.Indigo); /*/ / / 如果属性为空则初始化属性数据 / private void InitProperty() InitDefaultColors(); if (string.IsNullOrEmpty(Tit

9、le) 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 =

10、 0; List tempIndexList = new List(); for (int i = 0; i Count; 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 (int i = 1; i DataSour

11、ce0.Count + 1; i+) NameList.Add(第 + i.ToString() + 组); else for (int i = 1; i Count + 1; i+) NameList.Add(第 + i.ToString() + 组); if (LabelList.Count = 0) for (int i = 0; i Count; i+) LabelList.Add(含义 + i.ToString(); if (x_step = 0.0) x_step = 5; if (y_step = 0.0) y_step = 5; /*/ / / 画图 / / / / priva

12、te void zedGraphControl_RenderGraph(ZedGraphWeb zgw, System.Drawing.Graphics g, ZedGraph.MasterPane masterPane) InitProperty(); GraphPane myPane = masterPane0; myPane.Title.Text = Title; myPane.XAxis.Title.Text = XAxisTitle; myPane.YAxis.Title.Text = YAxisTitle; /if (true) / / DrawMessage(myPane, yi

13、afdhaskjhfasfksahfasdlhfaslf lasgfasglgsadi); / pane.AxisChange(g); / return; / switch (Type) case AnalyticsType.Line: DrawLine(myPane); break; case AnalyticsType.Bar: DrawBar(myPane); break; case AnalyticsType.Pie: DrawPie(myPane); break; case AnalyticsType.Line2: DrawLine2(myPane); break; case Ana

14、lyticsType.Curve: DrawCurve(myPane); break; case AnalyticsType.Curve2: DrawCurve2(myPane); break; default: break; masterPane.AxisChange(g); #region Draw /*/ / / 画折线图 / / private void DrawLine(GraphPane graphPane) for (int i = 0; i Count; i+) graphPane.AddCurve(NameListi, DataSourcei, Colorsi, Symbol

15、Type.None); string labels = LabelList.ToArray(); graphPane.XAxis.Scale.TextLabels = labels; graphPane.XAxis.Type = AxisType.Text; graphPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 166), 90F); graphPane.Fill = new Fill(Color.FromArgb(250, 250, 255); graphPane.YAxis.Scale.MajorStep = y_step; /*/ / / 画折线图,带阴影区域 / / private void DrawLine2(GraphPane graphPane)

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 建筑/环境 > 工程造价

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号