Adding unkown number of series at runtime

4 posts, 1 answers
  1. Martin Gartmann
    Martin Gartmann avatar
    51 posts
    Member since:
    Apr 2004

    Posted 30 Oct 2015 Link to this post

    Hi folks,

    i am working on a project where is want to plot multiple lineseries to compare racing times off different drivers on track during a race.

    My problem is that i don't know the number or the maximum number of drivers on track at design time.

    Of course i could add several series at runtime and simply don't fill the unused, but how can i manage this from code let's say in a For Next Loop.

    Suggestion in vb would be nice. Using

            Dim lineSeries As New LineSeries()
            For id = 0 To arrFahrer.Count - 1
                For i As Integer = 0 To arrFahrer(id).douRundenZeiten.Count - 2
                    rcvRundenzeiten.Series(id).DataPoints.Add(New CategoricalDataPoint(arrFahrer(id).douRundenZeiten.Item(i)))
                Next i
                rcvRundenzeiten.Series.Add(lineSeries)
            Next

    just creates one series with all points.

    Kind regards

     Martin

  2. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    711 posts

    Posted 02 Nov 2015 Link to this post

    Hi Martin,

    Thank you for writing.

    If I understand correctly you would like to display a separate series for each of the driver objects. In order to accomplish this task, you would need to create different series instances. In the provided code snippet, you are actually working with only one series and with each loop cycle you are overriding the data defined in the previous iteration. 

    Please check my example below: 
    Public Class Form1
        Sub New()
     
            InitializeComponent()
     
            Dim lineSeries As New LineSeries()
            lineSeries.DataPoints.Add(New CategoricalDataPoint(20, "Jan"))
            lineSeries.DataPoints.Add(New CategoricalDataPoint(22, "Apr"))
            lineSeries.DataPoints.Add(New CategoricalDataPoint(12, "Jul"))
            lineSeries.DataPoints.Add(New CategoricalDataPoint(19, "Oct"))
            Me.RadChartView1.Series.Add(lineSeries)
        End Sub
     
        Dim rand As New Random
        Private Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
            Dim lineSeries2 As New LineSeries()
            lineSeries2.DataPoints.Add(New CategoricalDataPoint(rand.Next(0, 30), "Jan"))
            lineSeries2.DataPoints.Add(New CategoricalDataPoint(rand.Next(0, 30), "Apr"))
            lineSeries2.DataPoints.Add(New CategoricalDataPoint(rand.Next(0, 30), "Jul"))
            lineSeries2.DataPoints.Add(New CategoricalDataPoint(rand.Next(0, 30), "Oct"))
            Me.RadChartView1.Series.Add(lineSeries2)
     
        End Sub
    End Class

    I am also sending you a gif file showing the result on my end.

    I hope this helps. Should you have further questions please do not hesitate to write back.
     
    Regards,
    Hristo Merdjanov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Martin Gartmann
    Martin Gartmann avatar
    51 posts
    Member since:
    Apr 2004

    Posted 02 Nov 2015 in reply to Hristo Merdjanov Link to this post

    Hi Hristo,
    ok that's what i want. My mistake when i tried  it, was to add Points to the same series instead of adding new ones.

    When i tried this before my DIM Lineseries was just done once outside my FOR NEXT Loop.

    Because the series are all part of the chartview i can switch them on/off (visible) just to compare a few, correct?

    Our usage would be for example, to compare the evolution of Laps times during a red/yellow flag period to controll that all drivers really stopped on track or slowed down (Yellow flag).

     Kind regards

     Martin Gartmann

     

     

  5. Answer
    Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    711 posts

    Posted 03 Nov 2015 Link to this post

    Hi Martin,

    Thank you for writing back.

    I am glad that my suggestion fits your local setup. In regards to your question, yes you can hide a particular series once it is added to RadChartView. In order to perform this task, you would need to set its IsVisible property to false, e.g. like this: 
    Me.RadChartView1.Series.Last.IsVisible = False

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top