question

Hahhuh456-9068 avatar image
0 Votes"
Hahhuh456-9068 asked JiachenLiMFST-9349 commented

how to make a real time graph in visual studio , visual basic window form app

Hello,
I am trying to make a real time line graph with visual basic in visual studio 2022 window form app.
the data of the graph is being pulled from a CSV file. the file updates every 10 sec.
I want to make the graph only portray around 10 data points at a time.
the graph also needs to update when new data point come in, the old data point should not be shown in the graph anymore

https://drive.google.com/file/d/1JwjiqNaGC3Jb3GmQuwSjqY2ekR-TTECc/view?usp=sharing

Above is the link for the CSV file

dotnet-visual-basicwindows-forms
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


Did you consider using a Chart control, which is available in .NET Framework and is seen in Toolbox, and updating it using a timer or when new data arrive?


1 Vote 1 ·

Hi @Hahhuh456-9068 ,
May I know if you have got any chance to check my answer? I am glad to help if you have any other questions.

1 Vote 1 ·
Hahhuh456-9068 avatar image Hahhuh456-9068 JiachenLiMFST-9349 ·

hi JiachenLiMFST-9349
Thank you for the answer.

so how to do filtration process in CSV for DAY,WEEK,MONTH and plot data from there.

0 Votes 0 ·

Hi @Hahhuh456-9068 ,
It is recommended that you post a new question with the detailed description of the new problem.
Thank you for your cooperation.

0 Votes 0 ·

1 Answer

JiachenLiMFST-9349 avatar image
1 Vote"
JiachenLiMFST-9349 answered

Hi @Hahhuh456-9068 ,
You can refer to the following code.

 Imports System.IO
 Imports System.Windows.Forms.DataVisualization.Charting
    
 Public Class Form1
     Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
         Chart1.Series(0).ChartType = SeriesChartType.Line
         Timer1.Interval = 1000
         If Timer1.Enabled = False Then
             Timer1.Enabled = True
         Else
             Timer1.Enabled = False
         End If
     End Sub
    
     Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
         Chart1.Series(0).Points.Clear()
         Dim fName = "C:\Yourfolder\Agriculture_Temp_Log.csv"
         If File.Exists(fName) = True Then
             Dim tmpstream As StreamReader = File.OpenText(fName)
             Dim TextLine() As String = tmpstream.ReadToEnd().Split(Environment.NewLine)
             For X = TextLine.Length - 12 To TextLine.Length - 2  'reading only the last 10 lines
                 Dim strline = TextLine(X).Split(",")
                 Chart1.Series(0).Points.AddXY(strline(1), CDbl(strline(2)))
             Next
             tmpstream.Close()
         Else
             MsgBox("file doesn't exist")
         End If
     End Sub
 End Class

Best Regards.
Jiachen Li


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.