首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

小弟我用的是dotnetCHARTING.dll 控件

2012-09-25 
我用的是dotnetCHARTING.dll 控件我想用dotnetCHARTING.dll 控件来显示曲线图,经过添加控件dotnetCHARTING

我用的是dotnetCHARTING.dll 控件
我想用dotnetCHARTING.dll 控件来显示曲线图,经过添加控件dotnetCHARTING.dll后,在ShowData类当中写了一些各种图形的方法,在页面代码中调用。ShowData中的代码如下:using System;
using System.Data;
using System.Configuration;
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;
using System.Data;
using System.Text;
using System.Collections;
using dotnetCHARTING;

/// <summary>
///ShowData 的摘要说明
/// </summary>
public class ShowData
{
  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; }
  }

  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;
  }

  /**/
  /// <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;
  }

  /**/
  /// <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;
  }


  /**/
  /// <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;
  }
}
页面代码如下:
using System;
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 System.Data.SqlClient;
using System.Collections;
using dotnetCHARTING;

public partial class _Default : System.Web.UI.Page 
{
  protected void Page_Load(object sender, EventArgs e)
  {
  ShowData show = new ShowData();
  show.Title = "2012年各月的消费情况统计";
  show.XTitle = "月份";
  show.YTitle = "金额(万元)";
  show.PicHight = 300;
  show.PicWidth = 600;
  show.SeriesName = "具体详情";
  show.PhaysicalImagePath = "ChartImages";

  String sqlconn = "server = localhost ;uid = sa;pwd =000;database =AAAA;Trusted_Connection = no;";
  SqlConnection myconnection = new SqlConnection(sqlconn);
  myconnection.Open();
  string sql = "SELECT YF ,SL FROM abc ";
  SqlCommand mycommand = new SqlCommand(sql, myconnection);
  SqlDataAdapter adapter = new SqlDataAdapter();
  adapter.SelectCommand = mycommand;
  DataSet ds = new DataSet();
  DataTable dt = ds.Tables[0];
  show.DataSource = dt;
  show.CreateLine(this.Chart1);  
  }
 

}

  运行以后出现DataTable dt = ds.Tables[0];报错,说是“无法找到表0” 这是怎么回事呢?还请各位指教啊!
 

[解决办法]
DataSet ds = new DataSet();
DataTable dt = ds.Tables[0];

你刚给它实例化一个数据集...里面为空的 当然会报找不到表0
DataSet ds = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.Fill(ds);
[解决办法]
js/highcharts.js
找JS的highcharts,使用更加方便

热点排行