Infragistics Ultrachart:使用DataTable中的数据填充XY数据系列

时间:2010-11-03 18:53:24

标签: c# .net infragistics

有没有人使用Infragistics UltraChart?我正在尝试将具有高程监视器数据的DataTable绑定到Windows窗体中的折线图。

从下面的代码中可以看出,我已经定义了DataSet和DataTable,并且已经开始设置图表的属性,但我不确定如何将DataTable表与图表中的XYDataPointCollection系列联系起来。基本上我希望能够绘制数据表中两个字段的一条线:“dateTime”(x轴)和指定日期范围的“gwElevation”(y轴)。

}       GroundwaterMonitorDataSet gwMonDataSet = new GroundwaterMonitorDataSet();       DataTable gwMonDataTable = new DataTable();       gwMonDataTable = gwMonDataSet.Tables.Add(“P-14-01_Data”);

  this.chartGwData.ChartType = Infragistics.UltraChart.Shared.Styles.ChartType.LineChart;
  Infragistics.UltraChart.Data.Series.XYDataPointCollection gwMonSeries = new Infragistics.UltraChart.Data.Series.XYDataPointCollection();

  chartGwData.LineChart.DrawStyle = Infragistics.UltraChart.Shared.Styles.LineDrawStyle.Solid;
  chartGwData.LineChart.StartStyle = Infragistics.UltraChart.Shared.Styles.LineCapStyle.Round;
  chartGwData.LineChart.EndStyle = Infragistics.UltraChart.Shared.Styles.LineCapStyle.Flat;
  chartGwData.LineChart.NullHandling = Infragistics.UltraChart.Shared.Styles.NullHandling.DontPlot;
  chartGwData.LineChart.Thickness = 3;

  this.chartGwData.DataSource = gwMonDataTable;
  this.chartGwData.DataBind();

}

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

好吧,我终于把它弄清楚了:

首先必须创建一个EnumerableRowCollection。我使用linq查询创建了一个,该查询从我的DataSet中的表中读取:

//create EnumerableRowCollection using the linq query on the DataSet table
gwMonDataTable = gwMonDataSet.P1401;
      EnumerableRowCollection<DataRow> qrySelectGwMonRecords =
        (from g in gwMonDataTable.AsEnumerable()
         where g.Field<DateTime>("readingDate") >= clndrGwMonStart.Value && g.Field<DateTime>("readingDate")<= clndrGwMonEnd.Value
         select g);

然后我创建一个NumericTimeSeries,它使用foreach循环填充:

//create NumericTimeSeries; populate using foreach loop
Infragistics.UltraChart.Resources.Appearance.NumericTimeSeries gwElevSeries = new Infragistics.UltraChart.Resources.Appearance.NumericTimeSeries();
      foreach (DataRow gwElevDr in qrySelectGwMonRecords)
      {
        gwElevSeries.Points.Add(new Infragistics.UltraChart.Resources.Appearance.NumericTimeDataPoint(System.DateTime.Parse(gwElevDr.ItemArray[2].ToString()),System.Double.Parse(gwElevDr.ItemArray[8].ToString()),"C",false));
      }

现在可以将NumericTimeSeries添加到UltraChart中:

//add the data series to the chart as the data source
chartGwData.Series.Add(gwElevSeries);