·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> ASP.NET网站开发 >> ASP.NET基于donetCHARTING的自动报表
1,首先需要添加引用ChartExtents.dll和donetCHARTING.dll,资源百度大把。
2,配置图片生成类。
1 using System; 2 using System.Data; 3 using System.Collections; 4 using System.Collections.Generic; 5 using System.Configuration; 6 using System.Web; 7 using dotnetCHARTING; 8 9 namespace ting.Models.BLL 10 { 11 public class Charting 12 { 13 PRivate string _phaysicalimagepath;//图片存放路径 14 private string _title; //图片标题 15 private string _xtitle;//图片x座标名称 16 private string _ytitle;//图片y座标名称 17 private string _seriesname;//图例名称 18 private int _picwidth;//图片宽度 19 private int _pichight;//图片高度 20 private SeriesType _type;//统计图类型(柱形,线形等) 21 private bool _use3d;//是否显示成3维图片 22 private SeriesCollection _dt;//统计图数据源 23 private string _filename;//统计图片的名称(不包括后缀名) 24 25 /**/ 26 /// <summary> 27 /// 图片存放路径 28 /// </summary> 29 public string PhaysicalImagePath 30 { 31 set { _phaysicalimagepath = value; } 32 get { return _phaysicalimagepath; } 33 } 34 /**/ 35 /// <summary> 36 /// 图片标题 37 /// </summary> 38 public string Title 39 { 40 set { _title = value; } 41 get { return _title; } 42 } 43 /**/ 44 /// <summary> 45 /// 图片x座标名称 46 /// </summary> 47 public string XTitle 48 { 49 set { _xtitle = value; } 50 get { return _xtitle; } 51 } 52 /**/ 53 /// <summary> 54 /// 图片y座标名称 55 /// </summary> 56 public string YTitle 57 { 58 set { _ytitle = value; } 59 get { return _ytitle; } 60 } 61 62 /**/ 63 /// <summary> 64 /// 图例名称 65 /// </summary> 66 public string SeriesName 67 { 68 set { _seriesname = value; } 69 get { return _seriesname; } 70 } 71 /**/ 72 /// <summary> 73 /// 图片宽度 74 /// </summary> 75 public int PicWidth 76 { 77 set { _picwidth = value; } 78 get { return _picwidth; } 79 } 80 /**/ 81 /// <summary> 82 /// 图片高度 83 /// </summary> 84 public int PicHight 85 { 86 set { _pichight = value; } 87 get { return _pichight; } 88 } 89 90 /// <summary> 91 /// 统计图类型(柱形,线形等) 92 /// </summary> 93 public SeriesType Type 94 { 95 set { _type = value; } 96 get { return _type; } 97 } 98 99 /// <summary>100 /// 是否将输出的图片显示成三维101 /// </summary>102 public bool Use3D103 {104 set { _use3d = value; }105 get { return _use3d; }106 }107 108 /// <summary>109 /// 对比图形数据源110 /// </summary>111 public SeriesCollection DataSource112 {113 114 set { _dt = value; }115 get { return _dt; }116 }117 118 /// <summary>119 /// 生成统计图片的名称120 /// </summary>121 public string FileName122 {123 set { _filename = value; }124 get { return _filename; }125 }126 127 128 /// <summary>129 /// 生成统计图片130 /// </summary>131 /// <param name="chart"></param>132 /// <param name="type">图形类别,如柱状,折线型</param>133 public void CreateStatisticPic(dotnetCHARTING.Chart chart)134 {135 chart.Title = this.Title;136 chart.XAxis.Label.Text = this.XTitle;137 chart.YAxis.Label.Text = this.YTitle;138 chart.TempDirectory = this.PhaysicalImagePath;139 chart.FileManager.FileName = this.FileName;140 chart.Width = this.PicWidth;141 chart.Height = this.PicHight;142 chart.Type = ChartType.Combo;143 chart.DefaultSeries.Type = this.Type; //统一使用默认的序列图类型属性144 chart.Series.Name = this.SeriesName;145 chart.SeriesCollection.Add(this.DataSource);146 chart.DefaultSeries.DefaultElement.ShowValue = true;147 chart.ShadingEffect = true;148 chart.Use3D = this.Use3D;149 chart.Series.DefaultElement.ShowValue = true;150 }151 }152 }View Code
3,新建一个ASP.NET页面,前台代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Statistics.aspx.cs" Inherits="ting.Views.Statistics" %><%@ 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> </div> <p> 请选择报表类型:<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"> </asp:DropDownList> </p> </form></body></html><script type="text/javascript"> var obj = document.getElementsByTagName("map")[0]; obj.parentNode.removeChild(obj); //屏蔽隐藏的链接</script>View Code
后台代码如下:
using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using System.Drawing;using dotnetCHARTING;using ting.Models.BLL;namespace ting.Views{ public partial class Statistics : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { Drawing("Bar"); DropDownList1.Items.Add(new ListItem("AreaLine", "AreaLine")); DropDownList1.Items.Add(new ListItem("Bar", "Bar")); DropDownList1.Items.Add(new ListItem("Column", "Column")); DropDownList1.Items.Add(new ListItem("Cylinder", "Cylinder")); DropDownList1.Items.Add(new ListItem("Line", "Line")); DropDownList1.Items.Add(new ListItem("Marker", "Marker")); DropDownList1.Items.Add(new ListItem("Spline", "Spline")); } } private v