Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to hide line2 show line1 when btn1 is clicked
how to hide line1 show line2 when btn2 is clicked

VB
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    For Each line As String In IO.File.ReadAllLines("C:\TestFolder1\123.txt")
        Dim points() As Double = Array.ConvertAll(line.Split(","c), Function(s) CDbl(s))
        Chart1.Series("Energy").Points.AddXY(points(2), points(0))
    Next
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    For Each line As String In IO.File.ReadAllLines("C:\TestFolder1\123.txt")
        Dim points() As Double = Array.ConvertAll(line.Split(","c), Function(s) CDbl(s))
        Chart1.Series("Power").Points.AddXY(points(2), points(1))
    Next
End Sub
Posted

1 solution

Try this

VB
Private Sub Button1_Click_1(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    'Add this line
    Chart1.Series("Power").Points.Clear()

    For Each line As String In IO.File.ReadAllLines("C:\TestFolder\123.txt")
        Dim points() As Double = Array.ConvertAll(line.Split(","c), Function(s) CDbl(s))
        Chart1.Series("Energy").Points.AddXY(points(0), points(0))
    Next
End Sub

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
    'Add this Line
    Chart1.Series("Energy").Points.Clear()

    For Each line As String In IO.File.ReadAllLines("C:\TestFolder\123.txt")
        Dim points() As Double = Array.ConvertAll(line.Split(","c), Function(s) CDbl(s))
        Chart1.Series("Power").Points.AddXY(points(1), points(0))
    Next
End Sub


This does not remove the series, but just clears the data from the chart.
To toggle the legends you can add the following to the respective button events.
VB
'In Button1 Click event add
Chart1.Series("Power").IsVisibleInLegend = False
Chart1.Series("Energy").IsVisibleInLegend = True

'In button2 Click event add
Chart1.Series("Energy").IsVisibleInLegend = False
Chart1.Series("Power").IsVisibleInLegend = True

[Edit] Add addtional code.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900