I am attempting to fill a DataTable with columns of numbers from a CSV to create lines on a third party chart control called Zedgraph. The problem is, the control keeps plotting one-to-one lines of point counts (in other words, if the column has 400 points, it plots a straight line from 0,0 to 400,400). I believe it is doing this because the data in my table is still being input as type String, which it shouldn't given the Cdbl(Var(x)) function I have written in. Why do you think my table values are still of type String?
Imports ZedGraph
Public Class Form1
Private Sub CreateDataset(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim DataSet As New DataSet
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
DataSet = getCsvToDataset(OpenFileDialog1.FileName)
End If
Call ChartFill(DataSet)
End Sub
Private Sub ChartFill(ByVal DS As DataSet)
Dim ChartPane As GraphPane = ZG1.GraphPane
Dim dspl As New DataSourcePointList
With dspl
.DataSource = DS.Tables(0)
.XDataMember = "Time Slot"
.YDataMember = "X1 1000 Air"
End With
Dim line1 As CurveItem
line1 = ChartPane.AddCurve("X1 1000 Air", dspl, Color.Aquamarine)
ChartPane.AxisChange()
End Sub
Private Shared Function getCsvToDataset(ByVal strPath As String) As DataSet
Dim strLine As String
Dim strArray As String()
Dim charArray As Char() = New Char() {","c}
Dim ds As New DataSet()
Dim dt As DataTable = ds.Tables.Add("TheData")
Dim aFile As New IO.FileStream(strPath, IO.FileMode.Open)
Dim sr As New IO.StreamReader(aFile)
strLine = sr.ReadLine()
strArray = strLine.Split(charArray)
For x As Integer = 0 To strArray.GetUpperBound(0)
dt.Columns.Add(strArray(x).Trim())
Next
strLine = sr.ReadLine()
While strLine IsNot Nothing
strArray = strLine.Split(charArray)
Dim dr As DataRow = dt.NewRow()
For i As Integer = 0 To strArray.GetUpperBound(0)
dr(i) = strArray(i).Trim()
If dr(i) <> "" Then
dr(i) = CDbl(Val(dr(i)))
End If
Next
dt.Rows.Add(dr)
strLine = sr.ReadLine()
End While
sr.Close()
Dim ds2 As New DataSet
Dim dt2 As DataTable = ds2.Tables.Add("MoreData")
Return (ds)
End Function
End Class
!--removed tag-->
No one has replied yet! Why not be the first?
Sign in or Join us (it's free).