MSChart with multi-datatables
-
I am binding MSChart to a dataset filled with 2 or more datatables. The MsChart is showing only the last datatable. My code is pasted below: ------------------------------------------------------- Private Sub ProductionChart() 'use collection to collect Selected product ' Dim Col As New Collection For Each lst As ListItem In chkWStringList.Items If lst.Selected Then Col.Add(lst.Text, lst.Text) End If Next oDs = New DataSet oDs = oTier.Production3(Col, Date.Parse(Date1.Text), Date.Parse(Date2.Text)) With Chart1 'Create new chart area for original series Dim ca As ChartArea = .ChartAreas.Add("ca2") .Titles(0).Text = "Chart" .Titles(0).Font = New Font("Trebuchet", 14, FontStyle.Bold) .ChartAreas("ca2").AxisX.TitleFont = New Font("Verdana", 10, FontStyle.Bold) .ChartAreas("ca2").AxisX.Title = "Date" .ChartAreas("ca2").AxisY.Title = "Production" '.Series.Clear() For j As Integer = 1 To Col.Count Dim oSeries As Series = New Series(Col.Item(j)) .Series.Add(oSeries) 'Give names to Series oSeries.Name = Col.Item(j).ToString .DataSource = oDs.Tables(j - 1) oSeries.ChartArea = ca.Name oSeries.ChartType = SeriesChartType.Line oSeries.XValueMember = "Date" oSeries.XValueType = Charting.ChartValueType.Date oSeries.YValueMembers = "Production" oSeries.BorderWidth = 3 Next .DataBind() .Visible = True End With End Sub
-
I am binding MSChart to a dataset filled with 2 or more datatables. The MsChart is showing only the last datatable. My code is pasted below: ------------------------------------------------------- Private Sub ProductionChart() 'use collection to collect Selected product ' Dim Col As New Collection For Each lst As ListItem In chkWStringList.Items If lst.Selected Then Col.Add(lst.Text, lst.Text) End If Next oDs = New DataSet oDs = oTier.Production3(Col, Date.Parse(Date1.Text), Date.Parse(Date2.Text)) With Chart1 'Create new chart area for original series Dim ca As ChartArea = .ChartAreas.Add("ca2") .Titles(0).Text = "Chart" .Titles(0).Font = New Font("Trebuchet", 14, FontStyle.Bold) .ChartAreas("ca2").AxisX.TitleFont = New Font("Verdana", 10, FontStyle.Bold) .ChartAreas("ca2").AxisX.Title = "Date" .ChartAreas("ca2").AxisY.Title = "Production" '.Series.Clear() For j As Integer = 1 To Col.Count Dim oSeries As Series = New Series(Col.Item(j)) .Series.Add(oSeries) 'Give names to Series oSeries.Name = Col.Item(j).ToString .DataSource = oDs.Tables(j - 1) oSeries.ChartArea = ca.Name oSeries.ChartType = SeriesChartType.Line oSeries.XValueMember = "Date" oSeries.XValueType = Charting.ChartValueType.Date oSeries.YValueMembers = "Production" oSeries.BorderWidth = 3 Next .DataBind() .Visible = True End With End Sub
aransiola wrote:
For j As Integer = 1 To Col.Count
aransiola wrote:
.DataSource = oDs.Tables(j - 1)
You get the last datatable as you have written code for that. You have started a for loop and keep changing the datasource depending on the index 'j'. Finally, when the loop comes to an end, 'j-1' has the last table pointed as a reference to datasource leading to data display of last table.
Sandeep Mewara Microsoft ASP.NET MVP [My latest Article]: Server side Delimiters in ASP.NET[^]
-
aransiola wrote:
For j As Integer = 1 To Col.Count
aransiola wrote:
.DataSource = oDs.Tables(j - 1)
You get the last datatable as you have written code for that. You have started a for loop and keep changing the datasource depending on the index 'j'. Finally, when the loop comes to an end, 'j-1' has the last table pointed as a reference to datasource leading to data display of last table.
Sandeep Mewara Microsoft ASP.NET MVP [My latest Article]: Server side Delimiters in ASP.NET[^]