Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. MSChart with multi-datatables

MSChart with multi-datatables

Scheduled Pinned Locked Moved ASP.NET
wpfwcf
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aransiola
    wrote on last edited by
    #1

    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

    S 1 Reply Last reply
    0
    • A aransiola

      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

      S Offline
      S Offline
      Sandeep Mewara
      wrote on last edited by
      #2

      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[^]

      A 1 Reply Last reply
      0
      • S Sandeep Mewara

        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[^]

        A Offline
        A Offline
        aransiola
        wrote on last edited by
        #3

        i am using the loop to add data source for each series i want the chart to show.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups