This is a migrated thread and some comments may be shown as answers.

Adding unkown number of series at runtime

3 Answers 76 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Martin Gartmann
Top achievements
Rank 2
Martin Gartmann asked on 30 Oct 2015, 06:49 PM

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

3 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 02 Nov 2015, 02:05 PM
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
0
Martin Gartmann
Top achievements
Rank 2
answered on 02 Nov 2015, 03:08 PM

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

 

 

0
Accepted
Hristo
Telerik team
answered on 03 Nov 2015, 09:43 AM
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
Tags
ChartView
Asked by
Martin Gartmann
Top achievements
Rank 2
Answers by
Hristo
Telerik team
Martin Gartmann
Top achievements
Rank 2
Share this question
or