title: VB.Net Chart Control - Can I bind data to different series from the different tables in my Dataset?
body: <p>I think my subject sums up what I am interested in knowing. I am looking to create a chart where Series1 is from Table1, Series2 is from Table2 in the given Dataset.</p>
  
  <p>My code below doesn't throw any errors, but it appears to be grabbing the data for each series from the first table.</p>
  
  <pre><code>    Imports System.Windows.Forms.DataVisualization.Charting
      Public Class Form1
      Public Sub New(ByVal ChartData As DataSet)
      ' This call is required by the designer.
      InitializeComponent()
      ' Add any initialization after the InitializeComponent() call.
      Dim ChartArea1 As ChartArea = New ChartArea()
      Dim Legend1 As Legend = New Legend()
      Dim DataSeries(ChartData.Tables.Count - 1) As Series
      Dim Chart1 = New Chart()
      Me.Controls.Add(Chart1)
  
      Chart1.ChartAreas.Add(ChartArea1)
      Chart1.Legends.Add(Legend1)
  
      Chart1.DataSource = ChartData
  
      For index As UShort = 0 To ChartData.Tables.Count - 1
          DataSeries(index) = New Series()
          DataSeries(index).Name = ChartData.Tables(index).TableName
          Chart1.Series.Add(DataSeries(index))
  
          Chart1.Series(index).XValueMember = ChartData.Tables(index).Columns(0).ColumnName
          Chart1.Series(index).YValueMembers = ChartData.Tables(index).Columns(1).ColumnName
      Next
  
      Chart1.Dock = DockStyle.Fill
      Chart1.TabIndex = 0
  
  
      End Sub
      End Class
  </code></pre>
  
  <p>Edit: Apparently I can get the results I expected by iterating through and setting the points from the data... but this approach seems like it wouldn't be speedy for large datasets. Is there a better way to be doing this?</p>
  
  <pre><code>    Imports System.Windows.Forms.DataVisualization.Charting
      Public Class Form1
  
      Public Sub New(ByVal ChartData As DataSet)
      ' This call is required by the designer.
      InitializeComponent()
      ' Add any initialization after the InitializeComponent() call.
      Dim ChartArea1 As ChartArea = New ChartArea()
      Dim Legend1 As Legend = New Legend()
      Dim DataSeries(ChartData.Tables.Count - 1) As Series
      Dim Chart1 = New Chart()
      Me.Controls.Add(Chart1)
  
      Chart1.ChartAreas.Add(ChartArea1)
      Chart1.Legends.Add(Legend1)
  
      For index As UShort = 0 To ChartData.Tables.Count - 1
          DataSeries(index) = New Series()
          DataSeries(index).Name = ChartData.Tables(index).TableName
          Chart1.Series.Add(DataSeries(index).Name)
  
          For RowIndex As UShort = 0 To ChartData.Tables(index).Rows.Count - 1
                      Chart1.Series(DataSeries(index).Name).Points.AddXY(ChartData.Tables(index).Rows(RowIndex).Item(0), ChartData.Tables(index).Rows(RowIndex).Item(1))
                  Next
              Next
  
              Chart1.Dock = DockStyle.Fill
              Chart1.TabIndex = 0
  
          End Sub
      End Class
  </code></pre>