rudhram

New member
Joined
May 2, 2011
Messages
1
Programming Experience
Beginner
Hi
I am working on a project which requires continuous plotting of power of a signal. VB.net will receive data through serial port and I want to plot these values as a bar graph. The values sent via the serial port is basically the power coefficients of the samples of the signal. I want to plot these values continuously in the form of a vertical bar graph. I need some help please.
Thank you
 
You will want to have a timer control set at about a 1 second interval and a PictureBox for the graph that is 103 height and has a border. Here is the code that worked for me:

VB.NET:
'pMain = PictureBox (Height=103, BorderStyle=FixedSingle)

Private _x As Integer = 0
Private _y As Integer = 1
Private _Value As Integer = 0

Private Sub tmrMain_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMain.Tick
   Dim p1 As New Point(_x, pMain.Height - _y) : _x += 10
   Dim p2 As New Point(_x, pMain.Height - (_Value + 3)) : _y = _Value + 3
   pMain.CreateGraphics.DrawLine(Pens.Black, p1, p2)
   If (_x + 10) > pMain.Width Then
       _x = 1
       pMain.CreateGraphics.Clear(pMain.BackColor)
   End If
End Sub

You can change the '_Value' variable to change the graph's value.

Hope this helps
-Josh
 
Here is the code that worked for me:

VB.NET:
'pMain = PictureBox (Height=103, BorderStyle=FixedSingle)

Private _x As Integer = 0
Private _y As Integer = 1
Private _Value As Integer = 0

Private Sub tmrMain_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMain.Tick
End Sub

It may work, but it is better to put most of that code in the pMain_Paint event, so you dont have to keep using CreateGraphics. Therefore, it would look something like :-

VB.NET:
    Private Sub tmrMain_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMain.Tick
        pMain.Refresh()
    End Sub

    Private Sub pMain_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles pMain.Paint
        With e.Graphics
            Dim p1 As New Point(_x, pMain.Height - _y) : _x += 10
            Dim p2 As New Point(_x, pMain.Height - (_Value + 3)) : _y = _Value + 3
            .DrawLine(Pens.Black, p1, p2)
            If (_x + 10) > pMain.Width Then
                _x = 1
                .Clear(pMain.BackColor)
            End If
        End With
    End Sub
 
Back
Top