|
-
Jan 10th, 2010, 04:10 AM
#1
Thread Starter
Lively Member
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.
-
Jan 10th, 2010, 04:26 AM
#2
Thread Starter
Lively Member
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 ?
-
Jan 10th, 2010, 07:31 AM
#3
Re: [RESOLVED] Converting voltage level into graphical display
 Originally Posted by catherine0136
[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:
Dim xAxisLength As Integer = 210 'and then, as before: 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.
-
Jan 10th, 2010, 08:09 PM
#4
Thread Starter
Lively Member
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?
-
Jan 10th, 2010, 08:44 PM
#5
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
-
Jan 11th, 2010, 05:52 AM
#6
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
-
Jan 11th, 2010, 08:42 PM
#7
Thread Starter
Lively Member
Re: [RESOLVED] Converting voltage level into graphical display
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|