Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleDraw a simple log graph
Keywordsgraph, draw, log, log graph
CategoriesGraphics
 
Use the Scale method to define a convenient scale. Then plot using Log(X) instead of X.
 
Private Sub Form_Load()
Dim i As Integer
Dim X As Single
Dim Y As Single

    Picture1.Scale (-1, 10)-(10, -1)
    
    ' Draw X axis.
    For i = 1 To 10
        X = Log(i)
        Picture1.Line (X, 10)-(X, -1), RGB(128, 128, 128)
    Next i
    Picture1.CurrentY = 0
    Picture1.Print "10"
    
    For i = 11 To 100 Step 10
        X = Log(i)
        Picture1.Line (X, 10)-(X, -1), RGB(128, 128, 128)
    Next i
    Picture1.CurrentY = 0
    Picture1.Print "100"
    
    For i = 200 To 1000 Step 100
        X = Log(i)
        Picture1.Line (X, 10)-(X, -1), RGB(128, 128, 128)
    Next i
    Picture1.CurrentY = 0
    Print Format$(1000)
    Picture1.Print "1000"

    Picture1.Line (-10, 0)-(10, 0), RGB(128, 128, 128)
    
    ' Draw Y axis.
    Picture1.Line (0, -10)-(0, 10)
    For i = -9 To 9
        Picture1.Line (-0.25, i)-(0.25, i)
    Next i
    
    ' Draw X = 2^Y.
    Picture1.ForeColor = vbRed
    Y = 0
    X = 1
    Picture1.CurrentX = Log(X)
    Picture1.CurrentY = Y
    For Y = 1 To 10 Step 0.25
        X = 2 ^ Y
        Picture1.Line -(Log(X), Y)
    Next Y
    Picture1.CurrentX = 0.2
    Picture1.CurrentY = 9
    Picture1.Print "X = 2^Y"

    ' Draw X = Y^3.
    Picture1.ForeColor = vbBlue
    Y = 1
    X = 1
    Picture1.CurrentX = Log(X)
    Picture1.CurrentY = Y
    For Y = 1 To 10 Step 0.25
        X = Y * Y * Y
        Picture1.Line -(Log(X), Y)
    Next Y
    Picture1.CurrentX = 0.2
    Picture1.CurrentY = 10
    Picture1.Print "X = Y^3"
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated