標籤:
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(Arraylist list) { 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: [email protected] * 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; } }}
dotnetcharting 產生柱狀圖,餅圖等統計圖