Results 1 to 6 of 6

Thread: Charting/Graphing

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2001
    Posts
    61

    Question 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

  2. #2
    pjvdg
    Guest
    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.

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2001
    Posts
    61
    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?

  4. #4
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    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

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2001
    Posts
    61
    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"

  6. #6

    Thread Starter
    Member
    Join Date
    Jan 2001
    Posts
    61
    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
  •  



Click Here to Expand Forum to Full Width