I must be doing something wrong. When I add a second series it overwrites the original. I think it has something to do with the datatables generating their own axis values. Any ideas for a workaround? I just want to have both series on one chart with reasonable scale.
The Datagridview is irrelevant here, I was just using it to check the datatable was working.
Thanks for looking :)
The Datagridview is irrelevant here, I was just using it to check the datatable was working.
Code:
Public Class Form1
Dim count As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dt As New DataTable
Dim x As Double = 0
Dim y As Double = 0
Dim i As Double = 0
dt.Columns.Add("ColumnA")
dt.Columns.Add("ColumnB")
Dim firstrow As DataRow = dt.NewRow
firstrow.SetField(0, x)
firstrow.SetField(1, y)
dt.Rows.Add(firstrow)
Do Until i = 10
Dim row As DataRow = dt.NewRow
i = i + 1
x = x + 1
y = y + 1
row.SetField(0, x)
row.SetField(1, y)
dt.Rows.Add(row)
Loop
DataGridView1.DataSource = dt
Chart1.DataSource = dt
Chart1.Series(count).ChartType = DataVisualization.Charting.SeriesChartType.Spline
Chart1.Series(count).XValueMember = "ColumnA"
Chart1.Series(count).YValueMembers = "ColumnB"
Chart1.Series.Add(count)
count = count + 1
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim dt As New DataTable
Dim x As Double = 0
Dim y As Double = 0
Dim i As Double = 0
dt.Columns.Add("ColumnA")
dt.Columns.Add("ColumnB")
Dim firstrow As DataRow = dt.NewRow
firstrow.SetField(0, x)
firstrow.SetField(1, y)
dt.Rows.Add(firstrow)
Do Until i = 10
Dim row As DataRow = dt.NewRow
i = i + 1
x = x + 1
y = y + 0.5
row.SetField(0, x)
row.SetField(1, y)
dt.Rows.Add(row)
Loop
DataGridView1.DataSource = dt
Chart1.DataSource = dt
Chart1.Series(count).ChartType = DataVisualization.Charting.SeriesChartType.Spline
Chart1.Series(count).XValueMember = "ColumnA"
Chart1.Series(count).YValueMembers = "ColumnB"
Chart1.Series.Add(count)
count = count + 1
End Sub
End Class