0

I am trying to bind a DataTable with a MS Chart. The Chart contains two series, that are two columns of the DataTable. I am using VB in Visual Studio 2010. Here is my code:

Public tableTempJDL As DataTable = New DataTable("TempJDL")    
'tableTempJDL is then filled

With Me.ChartBHKW
    .DataSource = tableTempJDL

    .Series(0).Name = oGebäude.Art
    .Series(0).ChartType = DataVisualization.Charting.SeriesChartType.Spline
    .Series(1).Name = oBHKW.Modell
    .Series(1).ChartType = DataVisualization.Charting.SeriesChartType.Spline

    .Series(0).XValueMember = Convert.ToString(tableTempJDL.Columns("Stunden"))
    .Series(0).YValueMembers = Convert.ToString(tableTempJDL.Columns("PthObjekt"))

    .Series(1).XValueMember = Convert.ToString(tableTempJDL.Columns("Stunden"))
    .Series(1).YValueMembers = Convert.ToString(tableTempJDL.Columns("PthBHKW"))

    .DataBind() '<-- ArgumentOutOfRangeException
End With

I get an ArgumentOutOfRangeException error: "Only 1 Y values can be set for this data series". And this even though I have two series in my Chart settings.

I would like to avoid to build the chart myself, and I really need two series, not two points for each XValue.

Community
  • 1
  • 1
Nicolas
  • 1,151
  • 3
  • 15
  • 28

1 Answers1

0

The code is actually perfectly ok, except for the fact that the column "PthObjekt" does not exist.

I just find strange to get an error at the DataBind saying that I can't have a more than one series, instead of an error at the line

.Series(0).YValueMembers = Convert.ToString(tableTempJDL.Columns("PthObjekt"))

I don't understand how this line can be executed without error... Anyways.

Nicolas
  • 1,151
  • 3
  • 15
  • 28