I'm creating in Visual Basic an application in winforms with a Chart control that displays the values taken from different CSV files. After having selected the files, the graph appears as in the figure:
I've noticed that blue vertical lines are created when a value in the series is missing. How can I fix?
This is my code:
Dim openFileDialog1 As New OpenFileDialog With {
.Filter = "CSV files (*.csv)|*.csv",
.FilterIndex = 1,
.Multiselect = True,
.Title = "Select only CSV files"
}
If openFileDialog1.ShowDialog() = DialogResult.OK Then
Chart1.Visible = True
If Chart1.Series.Count > 0 Then
Chart1.Series.Clear()
End If
Dim fileCounter As Integer = 0
For Each file As String In openFileDialog1.FileNames
fileCounter += 1
Dim lineCounter As Integer = 0
Dim sr As New StreamReader(file)
Dim currentLine As String
While sr.Peek() >= 0
currentLine = sr.ReadLine()
lineCounter += 1
If lineCounter = 1 Then
Dim series As New Series With {
.Name = Path.GetFileNameWithoutExtension(file),
.ChartType = SeriesChartType.Spline
}
Chart1.Series.Add(series)
Else
Dim values() As String = currentLine.Split(",")
Dim timers As String = values(0)
Dim speed As Double = Double.Parse(values(1))
Chart1.Series(fileCounter - 1).Points.AddXY(timers, speed)
End If
End While
sr.Close()
Next
Chart1.Series(0).ChartType = SeriesChartType.Spline
End If