Results 1 to 8 of 8

Thread: Making a simple graph from a database

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    UK
    Posts
    66
    I have a database table as:

    Code:
    COMMENT     VOTES
    Great       5
    OK          10
    Rubbish     2
    . . . and I want to use this information to draw a very simple bar chart.

    Any ideas?

    Simon

    [Edited by SimonPearce on 04-16-2000 at 07:56 AM]

  2. #2
    New Member
    Join Date
    Apr 2000
    Posts
    4

    Data bound controls in VB


    I have a database table as:

    Code:
    COMMENT     VOTES
    Great       5
    OK          10
    Rubbish     2
    . . . and I want to use this information to draw a very simple bar chart.

    Any ideas?

    Simon

    [Edited by SimonPearce on 04-16-2000 at 07:56 AM]
    Look into using data bound controls DAO and ADO.

    Place a Chart on a simple form. Add a Data Control. In this case add a DAO control. Create a ODBC link to you database. IN your Database create a query to supply your data. In VB use this as the recordset. The rest of the details is in the VB docs.

    Microsoft wants you to use Data Binding for record access. It can get tricky so read carefully.


  3. #3
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    Chart controls or line controls are nice and easy, this looks sort of like the sort of thing to appear on a web page though so (I'm guessing here, it's the alcohol talking) in ASP you can set the widths of a 1 pixel wide picture to create a graph on a web page...

    Ignore me if I'm going in the wrong direction

  4. #4
    Guest

    Lightbulb Fast Barchart

    Hello

    You could use an array of label controls also for a quick and dirty barchart:

    Code:
      ' set labels up
      Label1(0).BackColor = QBColor(4)
      Label1(1).BackColor = QBColor(1)
      Label1(2).BackColor = QBColor(6)
      
      ' multiply 100 for effect
      Label1(0).Width = 100 * Var1
      Label1(1).Width = 100 * Var2
      Label1(2).Width = 100 * Var3
    I've used this when I don't want to have all the overhead for the chart control.

    Hope this helps,

    Roger

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    UK
    Posts
    66

    Thumbs up

    That's great - just what I needed

    Simon


    Hello

    You could use an array of label controls also for a quick and dirty barchart:

    Code:
      ' set labels up
      Label1(0).BackColor = QBColor(4)
      Label1(1).BackColor = QBColor(1)
      Label1(2).BackColor = QBColor(6)
      
      ' multiply 100 for effect
      Label1(0).Width = 100 * Var1
      Label1(1).Width = 100 * Var2
      Label1(2).Width = 100 * Var3
    I've used this when I don't want to have all the overhead for the chart control.

    Hope this helps,

    Roger

  6. #6
    Addicted Member
    Join Date
    Jul 1999
    Location
    Portland, OR.
    Posts
    226
    Hi RvA

    That is a good idea.
    My Q. is how about the following code:

    Label1(0).Height = 100 * Var1

    This would take the bar downward! And it wouldn't take a negative value to take it upward.

    I have done it, But it took too much to accomplish it!
    Any work around?

    Thanx.

  7. #7
    Guest

    Lightbulb

    Hello,

    Ok, Lyla I played around a little and I came up with this.

    Code:
      Dim I As Integer, iMaxHeight As Integer
      Dim iLabelOffset As Integer
      
      For I = 0 To Label1.UBound
        Label1(I).Visible = False ' hide them all
      Next I
      
      ' set there colors
      Label1(0).BackColor = QBColor(4)
      Label1(1).BackColor = QBColor(1)
      Label1(2).BackColor = QBColor(6)
      
      ' get the current offset
      iLabelOffset = Label1(0).Top - Label1(0).Height
      
      ' multiply 100 for effect
      Label1(0).Height = 100 * Var1
      Label1(1).Height = 100 * Var2
      Label1(2).Height = 100 * Var3
      
      ' find the tallest label
      For I = 0 To Label1.UBound
        If Label1(I).Height > iMaxHeight Then
          iMaxHeight = Label1(I).Height
        End If
      Next I
      
      ' set the height for all the labels
      For I = 0 To Label1.UBound
        Label1(I).Top = (iMaxHeight - Label1(I).Height) + iLabelOffset
        Label1(I).Visible = True
      Next I
    I don't know if this is any easier then what you came up with.

    Best

    Roger

  8. #8
    Addicted Member
    Join Date
    Jul 1999
    Location
    Portland, OR.
    Posts
    226
    Hi RvA.

    Same result, different method

    Label1(0).Top = Label1(0).Height + (Label1(2).Height - Label1(0).Height)
    Label1(1).Top = Label1(0).Height + (Label1(2).Height - Label1(1).Height)
    Label1(2).Top = Label1(0).Height + (Label1(2).Height - Label1(2).Height)

    Thanx again.


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