使用DotNetCharting控件生成报表统计图总结
生活随笔
收集整理的這篇文章主要介紹了
使用DotNetCharting控件生成报表统计图总结
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
步驟:
(1)首先下載dotnetcharting破解版本
(2)把\bin\dotnetCHARTING.dll添加到工具箱,并且添加引用;
(3)把控件拖到你的網頁上,然后添加引用using dotnetCHARTING;
(4)創建dotnetCHARTING操作類,以便在程序中調用
?
/// <summary> /// 根據數據動態生成圖形(柱形圖、餅圖、曲線圖)/// </summary>public class ShowData{#region 屬性private string _phaysicalimagepath;//圖片存放路徑private string _title; //圖片標題private string _xtitle;//圖片x座標名稱private string _ytitle;//圖片y座標名稱private string _seriesname;//圖例名稱private int _picwidth;//圖片寬度private int _pichight;//圖片高度private DataTable _dt;//圖片數據源/// <summary>/// 圖片存放路徑/// </summary>public string PhaysicalImagePath{set { _phaysicalimagepath = value; }get { return _phaysicalimagepath; }}/// <summary>/// 圖片標題/// </summary>public string Title{set { _title = value; }get { return _title; }}/// <summary>/// 圖片標題/// </summary>public string XTitle{set { _xtitle = value; }get { return _xtitle; }}/// <summary>/// 圖片標題/// </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 DataTable DataSource{set { _dt = value; }get { return _dt; }}#endregion#region 構造函數public ShowData(){//// TODO: 在此處添加構造函數邏輯// }public ShowData(string PhaysicalImagePath, string Title, string XTitle, string YTitle, string SeriesName){_phaysicalimagepath = PhaysicalImagePath;_title = Title;_xtitle = XTitle;_ytitle = YTitle;_seriesname = SeriesName;}#endregion#region 輸出柱形圖/**//// <summary>/// 柱形圖/// </summary>/// <returns></returns>public void CreateColumn(dotnetCHARTING.Chart chart){chart.Title = this._title;chart.XAxis.Label.Text = this._xtitle;chart.YAxis.Label.Text = this._ytitle;chart.TempDirectory = this._phaysicalimagepath;chart.Width = this._picwidth;chart.Height = this._pichight;chart.Type = ChartType.Combo;chart.Series.Type = SeriesType.Cylinder;chart.Series.Name = this._seriesname;chart.Series.Data = this._dt;chart.SeriesCollection.Add();chart.DefaultSeries.DefaultElement.ShowValue = true;chart.ShadingEffect = true;chart.Use3D = false;chart.Series.DefaultElement.ShowValue = true;}#endregion#region 輸出餅圖/**//// <summary>/// 餅圖/// </summary>/// <returns></returns>public void CreatePie(dotnetCHARTING.Chart chart){chart.Title = this._title;chart.TempDirectory = this._phaysicalimagepath;chart.Width = this._picwidth;chart.Height = this._pichight;chart.Type = ChartType.Pie;chart.Series.Type = SeriesType.Cylinder;chart.Series.Name = this._seriesname;chart.ShadingEffect = true;chart.Use3D = false;chart.DefaultSeries.DefaultElement.Transparency = 20;chart.DefaultSeries.DefaultElement.ShowValue = true;chart.PieLabelMode = PieLabelMode.Outside;chart.SeriesCollection.Add(getArrayData());chart.Series.DefaultElement.ShowValue = true;}private SeriesCollection getArrayData(){SeriesCollection SC = new SeriesCollection();DataTable dt = this._dt;for (int i = 0; i < dt.Rows.Count; i++){Series s = new Series();s.Name = dt.Rows[i][0].ToString();Element e = new Element();// 每元素的名稱e.Name = dt.Rows[i][0].ToString();// 每元素的大小數值e.YValue = Convert.ToInt32(dt.Rows[i][1].ToString());s.Elements.Add(e);SC.Add(s);}return SC;}#endregion#region 輸出曲線圖/// <summary>/// 曲線圖/// </summary>/// <returns></returns>public void CreateLine(dotnetCHARTING.Chart chart){chart.Title = this._title;chart.XAxis.Label.Text = this._xtitle;chart.YAxis.Label.Text = this._ytitle;chart.TempDirectory = this._phaysicalimagepath;chart.Width = this._picwidth;chart.Height = this._pichight;chart.Type = ChartType.Combo;chart.Series.Type = SeriesType.Line;chart.Series.Name = this._seriesname;chart.Series.Data = this._dt;chart.SeriesCollection.Add();chart.DefaultSeries.DefaultElement.ShowValue = true;chart.ShadingEffect = true;chart.Use3D = false;chart.Series.DefaultElement.ShowValue = true;}#endregion}?
(4)實例調用
ASPX頁面源碼:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestDemo._Default" %><%@ Register Assembly="dotnetCHARTING" Namespace="dotnetCHARTING" TagPrefix="dotnetCHARTING" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"><title></title> </head> <body><form id="form1" runat="server"><div><dotnetCHARTING:Chart ID="Chart1" runat="server"></dotnetCHARTING:Chart><dotnetCHARTING:Chart ID="Chart2" runat="server"></dotnetCHARTING:Chart><dotnetCHARTING:Chart ID="Chart3" runat="server"></dotnetCHARTING:Chart></div></form> </body> </html>ASPX.CS源碼
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using dotnetCHARTING;namespace TestDemo {public partial class _Default : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){#region 調用說明及范例//在要顯示統計圖的頁面代碼直接調用,方法類似如下: ShowData show = new ShowData();show.Title = "2012年各月消費情況統計";show.XTitle = "月份"; show.YTitle = "金額(萬元)";show.PicHight = 300;show.PicWidth = 600;show.SeriesName = "總金額";show.PhaysicalImagePath = "images";DataTable dt = new DataTable();dt.Columns.Add("month", typeof(string));dt.Columns.Add("money", typeof(string));dt.Columns["month"].AutoIncrement = true;for (int i = 1; i < 13; i++){DataRow dr = dt.NewRow();dr["month"] = i.ToString();dr["money"] = 100 * i;dt.Rows.Add(dr);}show.DataSource = dt;show.CreateColumn(this.Chart1);//顯示柱形圖show.CreateLine(this.Chart2); //顯示曲線圖show.CreatePie(this.Chart3); //顯示餅圖#endregion}} }運行結果:
轉載于:https://www.cnblogs.com/Loyalty/archive/2012/06/19/2554325.html
總結
以上是生活随笔為你收集整理的使用DotNetCharting控件生成报表统计图总结的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux查看内核版本、系统版本、系统位
- 下一篇: ldifde 神奇功效,对付英文系统下显