[Newbie Question] How to draw a linier graph?

nlks
01-30-2005, 12:26 PM
i would like to draw a linear graph which run in real time
the line will goes up and down continuosly,
the end of the line will follow by a new line,
i dont know what it's called but it should look sth like this:
./\.............
/..\.../\ .....
.....\/...\....
............\...
what component should I use and how ?

passel
01-31-2005, 09:04 PM
You could use a Picturebox and some drawing commands.

Just a quick example thrown together, so no comments.
No double buffering or other good stuff.

Just paste this code into a new project and add a command button and a picturebox.
Click the command button to start and stop the graph.

Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Dim ly As Single, y As Single, py As Single

Private Sub Command1_Click()
Static doit As Boolean
doit = Not doit
If doit Then Picture1.Cls: y = Picture1.ScaleHeight / 2: ly = y
Do While doit
DrawGraph
Sleep 10
DoEvents
Loop
End Sub

Private Sub DrawGraph()
Static vlineCtr As Integer
Dim sw As Long, sh As Long

sw = Picture1.ScaleWidth - 5
sh = Picture1.ScaleHeight
y = y + (10 * Rnd) - 5
If y > 0.8 * sh Then
y = 0.8 * sh
End If
If y < 0.2 * sh Then
y = 0.2 * sh
End If
BitBlt Picture1.hDC, 0, 0, sw, sh, Picture1.hDC, 4, 0, vbSrcCopy
Picture1.Line (sw, py)-(sw + 5, ly), Picture1.BackColor
Picture1.Line (sw, ly)-(sw + 5, y)
vlineCtr = (vlineCtr + 1) Mod 10
If vlineCtr = 0 Then
Picture1.Line (sw - 1, 0)-(sw - 1, sh)
End If
Picture1.Line (sw, 0.25 * sh)-Step(6, 0)
Picture1.Line (sw, 0.75 * sh)-Step(6, 0)

py = ly
ly = y
End Sub

Private Sub Form_Load()
Picture1.ScaleMode = vbPixels
End Sub

zelg37
01-31-2005, 11:23 PM
This is also called a strip chart (after the paper and mechnical pen machines that do roughly the same thing).

Here a post which references some ActiveX controls that do this sort of thing (and gives a link to BillSoo's Graphing tutorial) :
http://www.xtremevbtalk.com/showpost.php?p=628267

Some "stock ticker" demos are attached to this post:
http://www.xtremevbtalk.com/showpost.php?p=539659

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum