dotnetcharting 生成柱状图,饼图等统计图
DotNetCharting是一个非常棒的.NET图表控件,对中文支持非常好,而且操作方便,开发快速,既有for webform 也有for winform的,而且.net1.1和2.0都有支持。官方地址是http://www.dotnetcharting.com/
简单使用方法:
1.首先要搞定帮助文档:从官方网站下载解压后把dotnetcharting4.2for1.x目录设置成虚拟目录,.net1.1的环境,然后就可以看帮助示例了。
2.把\bin\dotnetCHARTING.dll添加到工具箱,并且添加引用
3.把控件拖到你的网页上,然后添加引用using dotnetCHARTING;就可以用了
4.说下简单的柱状图的用法(动态获取数据):它有个type属性决定是柱状图还是饼图或是其他,设置成Combo就是柱状图;
private void Drawing() { Charting show = new Charting(); show.Title = "MyChart"; show.YTitle = "Y Axis Label"; show.XTitle = "X Axis Label"; show.PicHight = 400; show.PicWidth = 400; show.SeriesName = "具体详情"; show.PhaysicalImagePath = @"~/pictrue"; //此为图片保存的路径,不存在则会无法显示(下同) show.FileName = "Combo.png"; show.Type = ChartType.Combo;//combo为柱状图,pie为饼图 show.Use3D = false; show.DataSource = GetDataSource(); show.CreateStatisticPic(this.Chart1); } private SeriesCollection GetDataSource() { SeriesCollection SC = new SeriesCollection(); Random myR = new Random(); for(int a = 0; a < 4; a++) { Series s = new Series(); s.Name = "Series " + a; for(int b = 0; b < 5; b++) { Element e = new Element(); e.Name = "E " + b; e.YValue = myR.Next(50); s.Elements.Add(e); } SC.Add(s); } }
/* * author: peace * email: peacechzh@126.com * date : 2009-4-18 */ using System; using System.Data; using System.Collections; using System.Collections.Generic; using System.Configuration; using System.Web; using dotnetCHARTING; namespace ChartExtents { /// <summary> /// Charting 的摘要说明 /// </summary> public class Charting { private string _phaysicalimagepath;//图片存放路径 private string _title; //图片标题 private string _xtitle;//图片x座标名称 private string _ytitle;//图片y座标名称 private string _seriesname;//图例名称 private int _picwidth;//图片宽度 private int _pichight;//图片高度 private ChartType _type;//统计图类型(柱形,线形等) private bool _use3d;//是否显示成3维图片 private SeriesCollection _dt;//统计图数据源 private string _filename;//统计图片的名称(不包括后缀名) /**/ /// <summary> /// 图片存放路径 /// </summary> public string PhaysicalImagePath { set { _phaysicalimagepath = value; } get { return _phaysicalimagepath; } } /**/ /// <summary> /// 图片标题 /// </summary> public string Title { set { _title = value; } get { return _title; } } /**/ /// <summary> /// 图片x座标名称 /// </summary> public string XTitle { set { _xtitle = value; } get { return _xtitle; } } /**/ /// <summary> /// 图片y座标名称 /// </summary> public string YTitle { set { _ytitle = value; } get { return _ytitle; } } /**/ /// <summary> /// 图例名称 /// </summary> public string SeriesName { set { _seriesname = value; } get { return _seriesname; } } /**/ /// <summary> /// 图片宽度 /// </summary> public int PicWidth { set { _picwidth = value; } get { return _picwidth; } } /**/ /// <summary> /// 图片高度 /// </summary> public int PicHight { set { _pichight = value; } get { return _pichight; } } /// <summary> /// 统计图类型(柱形,线形等) /// </summary> public ChartType Type { set { _type = value; } get { return _type; } } /// <summary> /// 是否将输出的图片显示成三维 /// </summary> public bool Use3D { set { _use3d = value; } get { return _use3d; } } /// <summary> /// 对比图形数据源 /// </summary> public SeriesCollection DataSource { set { _dt = value; } get { return _dt; } } /// <summary> /// 生成统计图片的名称 /// </summary> public string FileName { set { _filename = value; } get { return _filename; } } /// <summary> /// 生成统计图片 /// </summary> /// <param name="chart"></param> /// <param name="type">图形类别,如柱状,折线型</param> public void CreateStatisticPic(dotnetCHARTING.Chart chart) { chart.Title = this.Title; chart.XAxis.Label.Text = this.XTitle; chart.YAxis.Label.Text = this.YTitle; chart.TempDirectory = this.PhaysicalImagePath; chart.FileManager.FileName = this.FileName; chart.Width = this.PicWidth; chart.Height = this.PicHight; chart.Type = this.Type; //chart.Series.Type = this.Type;//生成对比的线型图时不适用 chart.DefaultSeries.Type = this.Type; //统一使用默认的序列图类型属性 chart.Series.Name = this.SeriesName; chart.SeriesCollection.Add(this.DataSource); chart.DefaultSeries.DefaultElement.ShowValue = true; chart.ShadingEffect = true; chart.Use3D = this.Use3D; chart.Series.DefaultElement.ShowValue = true; } } }