Results 1 to 20 of 20

Thread: [RESOLVED] Plotting Real Time Graph

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Resolved [RESOLVED] Plotting Real Time Graph

    Hello. I would like to seek guidance on to do a real time graph.

    Currently, my circuit is connected to a power supply and is connected to the computer via a RS232 cable. Voltage level is extracted and the real-time voltage level is plotted (see attached image) and it will keep moving.

    But you will realise that there isnt any time shown on the X-axis. I would like to display time in such a way:

    Each long marker will represent 1 second and there are 4 long marker, which will represent up to 4 seconds.

    When the (5th second) voltage is sense and the real-time voltage is drawn, i would like the new time (5th second) to replace into the 1st marker postion, the (6th second) to replace the 2nd marker position, so on and so forth. The replacement will continue.. ..


    As in i would want to have a moving real time. I am currently still doing research on how to do that.

    But in the mean time, if anyone of you have any suggestions / guidance on how to do that, i would really appreciate if you can post it.

    Thanks in advance!

    Attached is also the code on plotting the real-time voltage graph on a picturebox and also the timer coding for reference, if needed.

    Code:
      'Details of the graph layout 
            Dim Origin As New Point(50, 220)
            Dim xAxisLength As Integer = 210
            Dim yAxisLength As Integer = -250
    
            If voltsQ.Count > 2 Then
                'Turn the queue into an array:
                Dim voltsQarray As Single() = voltsQ.ToArray
    
                'Define an array of data points:
                Dim DataPoints(voltsQ.Count - 1) As Point
                Dim x, y As Integer
    
                'Fill in the array using the voltage readings:
                For i As Integer = 0 To voltsQ.Count - 1
                    'Get the volts value from the queue:
                    Dim v As Single = voltsQarray(i)
                    'Find the distance along the x axis:
                    x = Origin.X + CInt(i * xAxisLength / 40)
                    'find the height of the data point on the Y axis:
    
                    y = Origin.Y + CInt(v * yAxisLength / maxVolts)
                    'Put the point in the array
                    DataPoints(i) = New Point(x, y)
    
                Next
                'Draw the waveform:        
                e.Graphics.DrawCurve(Pens.Green, DataPoints)
            End If
    Timer coding:
    Code:
    'read the voltage and get value from RS232 interface
            Call OpenPORT1()
    
            Single.TryParse(TextBoxVoltage.Text, volts1)
            'add the new reading to the end of the queue
            voltsQ.Enqueue(volts1)
    
            'remove the old reading at the head of the queue, to keep max. 40 data points    
            If voltsQ.Count > 40 Then voltsQ.Dequeue()
    
            'update the display with the new data     
            Me.Refresh()
    Attached Images Attached Images  

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