Results 1 to 3 of 3

Thread: Making a multi series line chart

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2020
    Posts
    5

    Making a multi series line chart

    Hello I am making a projectile motion program and want to make it so when I click the plot button more than once, it creates multiple series. Currently I have it so when I click plot, it clears the previous series and plots the new one. I Honestly have spent a day thinking how to do this, and couldn't think of an idea, please help.

    Code:
    Protected Sub BTNSimulate_Click(sender As Object, e As EventArgs) Handles BTNSimulate.Click
            'Main Values that will be used 
            Dim Velocity, Angle, Gravity As Double
    
            'Initial Input Validation
            Dim IsValid As Boolean = False
            IsValid = ValidateInput(Velocity, Angle, Gravity)
            If IsValid = False Then
                Exit Sub
            End If
    
            'Turns degrees into radians, as its easier to do calcultions
            Angle = DegToRad(Angle)
    
            'Creates the chart
            CreateChart()
    
            'Creates a series
            CreateSeries()
    
            'Sets the maximum and minimum for the graph depending on the values maximum height and range
            Dim MaxHeightChart, MaxDistanceChart As Integer
            FindAxisSize(MaxHeightChart, MaxDistanceChart, Velocity, Angle, Gravity)
            SetChartMaxMin(MaxDistanceChart, MaxHeightChart)
    
            'plots the graph
            PlotGraph(Velocity, Angle, Gravity)
    
    End Sub
    
    Sub CreateSeries()
            Chart1.Series.Clear()
            Chart1.Series.Add("Line 1")
            Chart1.Series("Line 1").Color = Color.Red
            Chart1.Series("Line 1").ChartType = DataVisualization.Charting.SeriesChartType.Line
    End Sub 
    
    Sub CreateChart()
            Chart1.Titles.Clear()
            Chart1.ChartAreas.Clear()
            Chart1.Titles.Add("Motion of projectile")
            Chart1.ChartAreas.Add("Chart")
            With Chart1.ChartAreas("Chart")
                .AxisX.Title = "Distance (m)"
                .AxisX.MajorGrid.LineColor = Color.LightGray
                .AxisY.Title = "Height (m)"
                .AxisY.MajorGrid.LineColor = Color.LightGray
            End With
        End Sub

  2. #2
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    845

    Re: Making a multi series line chart

    Hello,

    Your sub CreateSeries() clear all serie before creating a new serie with the same name.

    replace
    Code:
    Chart1.Series.Clear()
    Chart1.Series.Add("Line 1")
    with

    Code:
    dim number =  Chart1.Series.count +1  ' verify when there is no serie if the result is zero or nothing, I don't remember. 
    Dim serie = "line_" & number.ToString
    Chart1.Series.Add(serie)
    and put

    Code:
    Chart1.Series.Clear()
    in a special button, if you want to clear the graph at some point.

    regards
    Last edited by Delaney; Sep 20th, 2020 at 01:47 PM.
    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
    “They did not know it was impossible so they did it” (Mark Twain)

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2020
    Posts
    5

    Re: Making a multi series line chart

    Yes! This is exactly what I needed. Thank you so much, now Im nearly finished with the main component of my school project. Hope you have a great day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width