Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleLet the user scroll through a very long graph
Keywordsgraph, long graph, scroll
CategoriesGraphics
 
Use a PictureBox's ScaleLeft, ScaleWidth, ScaleTop, and ScaleHeight properties to set its scale factors so it shows only the part of the graph that should be visible. Then draw only the area that should be visible at any given time.

With this method, you can make an "infinitely" wide graph without creating a huge PictureBox holding the entire graph.

 
' Draw the piece of the graph that should be visible now.
Private Sub DrawGraph()
Dim wid As Single
Dim hgt As Single
Dim xmin As Single
Dim xmax As Single
Dim X As Single
Dim Y As Single

    ' Clear.
    picGraph.Line (picGraph.ScaleLeft, _
        picGraph.ScaleTop)-Step(picGraph.ScaleWidth, _
        picGraph.ScaleHeight), picGraph.BackColor, BF

    ' Give the PictureBox a scale
    ' so we can draw in real coordinates.
    picGraph.ScaleMode = vbPixels
    wid = picGraph.ScaleWidth
    hgt = picGraph.ScaleHeight
    picGraph.ScaleTop = hgt / 2
    picGraph.ScaleHeight = -hgt
    xmin = scrGraph.Value
    xmax = xmin + wid
    picGraph.ScaleLeft = xmin
    picGraph.ScaleWidth = wid

    ' Draw the axis.
    picGraph.Line (xmin, 0)-(xmax, 0), vbBlack
    X = 25 * (xmin \ 25)
    Do While X < xmax
        X = X + 25
        If X Mod 100 = 0 Then
            picGraph.Line (X, 7)-Step(0, -14), vbBlack
            picGraph.CurrentX = X - picGraph.TextWidth(X) / _
                2
            picGraph.CurrentY = -10
            picGraph.Print X
        Else
            picGraph.Line (X, 3)-Step(0, -6), vbBlack
        End If
    Loop

    ' F(X) = 40 * Sin(X / 10) + 20 * Cos(X / 7)
    X = xmin
    picGraph.CurrentX = X
    picGraph.CurrentY = 40 * Sin(X / 10) + 20 * Cos(X / 7)
    Do While X < xmax
        X = X + 1
        picGraph.Line -(X, 40 * Sin(X / 10) + 20 * Cos(X / _
            7)), vbRed
    Loop

    ' F(X) = 20 * Sin(X / 20)
    X = xmin
    picGraph.CurrentX = X
    picGraph.CurrentY = 20 * Sin(X / 20)
    Do While X < xmax
        X = X + 1
        picGraph.Line -(X, 20 * Sin(X / 20)), vbBlue
    Loop

    ' F(X) = 40 * Sin(X / 11) * Cos(X / 13)
    X = xmin
    picGraph.CurrentX = X
    picGraph.CurrentY = 40 * Sin(X / 11) * Cos(X / 13)
    Do While X < xmax
        X = X + 1
        picGraph.Line -(X, 40 * Sin(X / 11) * Cos(X / 13)), _
            vbWhite
    Loop

    picGraph.Picture = picGraph.Image
End Sub
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated