Results 1 to 40 of 68

Thread: [RESOLVED] Converting voltage level into graphical display

Hybrid View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: [RESOLVED] Converting voltage level into graphical display

    Okie. Thanks for the help once again !

    I'll try it out tmr when i'm back to school.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: [RESOLVED] Converting voltage level into graphical display

    Code:
     'Details of the graph layout -- fill in your own values here!
    Dim Origin As New Point(200, 200)
    Dim xAxisLength As Integer = 300
    Dim yAxisLength As Integer = 150
    I need to clarify my doubts. =)
    For the above, you mentioned that i need to fill in my own values,
    so as in:

    >>
    Code:
    Dim Origin As New Point(200, 200).. 
    i replace the ( , ) value to the values of where the x and y line intersect each other ?


    >>
    Code:
    Dim xAxisLength As Integer = 300
    Dim yAxisLength As Integer = 150
    The code to draw the vertical and horizontal line is as shown below:
    Code:
     ' Drawing a vertical and a horizontal line 
       g.DrawLine(BluePen, 50, 225, 50, 15)   'vertical line
       g.DrawLine(BluePen, 50, 120, 260, 120)  'horizontal line
    So, i'll replace xAxisLength As Integer, yAxisLengthts into the values as shown above ?

  3. #3
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: [RESOLVED] Converting voltage level into graphical display

    Quote Originally Posted by catherine0136 View Post
    [CODE] i replace the ( , ) value to the values of where the x and y line intersect each other ?
    Exactly.

    Code:
    g.DrawLine(BluePen, 50, 120, 260, 120)  'horizontal line
    If that line is your X axis, it extends from point (50, 120) to point (260, 120), so must be 210 pixels long. You could fill in that 210 everywhere instead of xAxisLength, but it would be better to keep using the variable name instead:
    vb.net Code:
    1. Dim xAxisLength As Integer = 210
    2.  
    3. 'and then, as before:
    4.  
    5. x = Origin.X + CInt(i * xAxisLength / 40)
    The same obviously applies to the Y axis. This way there is just one place where you set the axis length. It will be easier to change you layout if you need to. After all, you may need to play around with these figures to get the graph looking right.

    You realize of course that xAxisLength is just a name I made up. An important part of the art of programming is thinking up good names for variables. To come to think of it, it would be better to replace that "40" by a variable to represent the number of data points to be plotted. In that case you would have to declare (with Dim or Private) whatever name you have chosen for the variable. You should do it outside the sub, for example with other variables near the top of the form code, because it is also referred to in the timer Tick sub.

    BB
    Last edited by boops boops; Jan 10th, 2010 at 07:49 AM.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: [RESOLVED] Converting voltage level into graphical display

    I had this error :
    Code:
    'ElementAt' is not a member of 'System.Collections.Generic.Queue(Of Single)'
    How do i resolve this?

  5. #5
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: [RESOLVED] Converting voltage level into graphical display

    That must be because you are using an older version of Visual Studio than 2008. I hadn't thought of that. It means the Paint sub I posted in #47 needs a couple of small changes. Add this before line 10 of the sub:

    Code:
    'Turn the queue into an array:
    Dim voltsQarray As Single() = voltsQ.ToArray
    and change the present line 17 to this:
    Code:
    Dim v As Single = voltsQarray(i)
    That should fix it. BB

  6. #6
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: [RESOLVED] Converting voltage level into graphical display

    I just spotted another error in the Paint sub: the code will fail if voltsQ is empty. In fact there is not much sense in trying to draw the curve until there are at least 3 data points in the queue. So you should enclose all the code after drawing the axes in this If statement:
    Code:
    If VoltsQ.Count > 2
    ...
    End If
    BB

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: [RESOLVED] Converting voltage level into graphical display

    Thanks for helping ! =)

    Am i right to place the VoltsQ.Count>2 as follows, please correct me if i'm wrong.

    Code:
    If VoltsQ.Count > 2
    
     'Put your code for drawing the axes etc. here.
    
    
                'Details of the graph layout -- fill in your own values here!
                Dim Origin As New Point(50, 119)
                Dim xAxisLength As Integer = 210
                Dim yAxisLength As Integer = -120
    
                '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

    Btw, after placing all the code into the program, this is what i observe [ please see attached image ] Hmm.. its still a straight line though but it is varying quantity against time. So i believe its correct ?
    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