Results 1 to 2 of 2

Thread: Plot graph for CSV file

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2014
    Posts
    30

    Plot graph for CSV file

    Dear all,

    I am trying to plot graph for CSV file. My file saved as current.csv andwhen open it look like this

    Code:
    Date          	TIME           	Watt-Hour	        Current
    26-09-2014	       10:09:55 AM	0.003933333	0.13
    26-09-2014	       10:10:10 AM	0.007866667	0.1
    26-09-2014	       10:10:25 AM	0.0114	        0.07
    26-09-2014 	10:10:40 AM	0.014533333	0.1
    26-09-2014	       10:10:55 AM	0.018266667	0.1
    26-09-2014	       10:11:10 AM	0.021         	0.1
    26-09-2014	       10:11:25 AM	0.024333333	0.07
    26-09-2014	       10:11:40 AM	0.028266667	0.13
    Now i wanted to import graph and plot intially time Vs watt-hour

    2) if i select time intervals hours then i should able to get grapgh betwen start and stop time
    3) similarly with date.


    TO get started with I need simple example where i can import and plot graph time Vs watt-hour

    Here i got simple example but . All are giving error . is any library need to be added

    But here he his taking first column data , I need second column data and 3rd cloumn data. How to change column data point here.

    Code:
     Private Sub OK_Pressed_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Pressed.Click
            Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser("Current.csv")
                MyReader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited
                MyReader.Delimiters = New String() {","}
                Dim currentRow As String()
                Dim CurrentPoint As Integer = 0
                Chart2.Series(0).Points.Clear()
                While Not MyReader.EndOfData
                    Try
                        currentRow = MyReader.ReadFields()
                        Dim D As String = currentRow(0)
                        Try
                            Dim Y As Double = CDbl(currentRow(2))
                            Chart2.Series(0).Points.AddY(Y)
                            Chart2.Series(0).Points(CurrentPoint).AxisLabel = D
                            CurrentPoint += 1
                        Catch ex As InvalidCastException
                            If CurrentPoint <> 0 Then
                                MsgBox("Item " & currentRow(2) & " is invalid.  Skipping")
                            End If
                        End Try
                    Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
                        If CurrentPoint <> 0 Then
                            MsgBox("Line " & ex.Message & " is invalid.  Skipping")
                        End If
                    End Try
                End While
            End Using
    
        End Sub
    End Class
    Last edited by AJITnayak; Sep 27th, 2014 at 01:22 AM. Reason: Code being added

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Plot graph for CSV file

    Are you using the Microsoft .NET chart control? What are you doing and what are the errors?

Tags for this Thread

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