|
-
Jun 12th, 2001, 02:10 PM
#1
Thread Starter
Member
Charting/Graphing
Hello all, I am trying to learn the graphic side of VB now and was looking for some help. I would like to start with a simple bar graph. Something like a voltage meter. I have a variable that will change and show me voltage. I would like to have like a bar graph that would move up and down based upon my variable. Any help in this matter would be greatly appreciated
Thanks in advance
PBSnake
-
Jun 12th, 2001, 03:14 PM
#2
That shouldn't be so hard:
blt a bitmap(for example 70x30, filled with green)
to the screen.
If your variable = 0 blt it once,
if it's = 2, blt one on top of the last one
if it's =3, etc.
(this isn't the best example since it's best that you keep the maximum value of your variable in mind, otherwise it could be too big to fit on the screen)
It's just a matter of working with x & y positions.
-
Jun 13th, 2001, 10:34 AM
#3
Thread Starter
Member
Please excuse me, this is new to me. Could you show me an example how to put it to the screen. And what would I use to create this bitmap?
-
Jun 13th, 2001, 12:49 PM
#4
PowerPoster
Open a new project, goto the code window of the form, select all and delete it. Then insert this code and run the project:
Code:
'Variables (Data of yer chart)
Dim DataCount As Long
Dim Data() As Single
Dim ActData As Long
Sub CreateSampleData()
Dim A As Long
'Create 6 bars
DataCount = 5
ReDim Data(DataCount)
'Randomize data
For A = 0 To DataCount
Data(A) = (100 * Rnd)
Next
End Sub
Sub DrawChart()
Dim A As Long
Dim OffsetX As Long
Dim OffsetY As Long
Dim BarDistance As Long
Dim BarWidth As Long
'Size and distance of bars
BarDistance = 20
BarWidth = 10
'Position of chart
OffsetX = 20
OffsetY = 100
'Clear form
Me.Cls
For A = 0 To DataCount
'Draw bar
Line (OffsetX + (A * BarDistance), OffsetY)-(OffsetX + (A * BarDistance) + BarWidth, OffsetY - Data(A)), _
QBColor(A), BF
Next
End Sub
Sub SetupForm()
With Me
'Setup window
.ScaleMode = vbPixels
'Size
.Width = 2500
.Height = 2200
'Center
.Move (Screen.Width - .Width) / 2, (Screen.Height - .Height) / 2
'Display window
.Show
End With
DoEvents
End Sub
Private Sub Form_Click()
'Next bar
ActData = ActData + 1
If ActData > DataCount Then: ActData = 0
End Sub
Private Sub Form_Load()
SetupForm
CreateSampleData
DrawChart
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'Modify data
Data(ActData) = Y
DrawChart
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Release memory
Erase Data
End Sub
-
Jun 13th, 2001, 02:13 PM
#5
Thread Starter
Member
Thank you very much! Thats what I was looking for. I will play with it and see if I understand all that is going on.
PBSnake
"If you don't do it!! someone else will"
-
Jun 13th, 2001, 02:39 PM
#6
Thread Starter
Member
Thank you very much! Thats what I was looking for. I will play with it and see if I understand all that is going on.
PBSnake
"If you don't do it!! someone else will"
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
|