HOWTO: Create Pie Charts Using the Circle Method in VB

Last reviewed: September 30, 1997
Article ID: Q153927
The information in this article applies to:
  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 16-bit and 32-bit, for Windows, version 4.0

SUMMARY

The Pinnacle-BPS Graph control shipping with Visual Basic gives users the ability to create pie charts. The Pinnacle-BPS is a relatively large control and uses a large amount of disk space on distribution disks. Therefore, the custom effects available are limited to the features of the control. The Circle method in the VBA language provides functionality to draw arcs and segments. By drawing segments, you can easily create a pie chart and add custom features as you require. Below is a code sample demonstrating how to do this.

MORE INFORMATION

  1. Start a new Visual Basic project. Form1 is created by default.

  2. Place a Command button on the form.

  3. Place a 200x200 pixel Picture box on the form.

  4. Add the following code to the Form1 code window:

          Option Explicit
    

          Public Sub DrawPiePiece(lColor As Long, fStart As Double, fEnd As
          Double)
    
            Const PI As Double = 3.14159265359
            Const CircleEnd As Double = -2 * PI
            Dim dStart As Double
            Dim dEnd As Double
            Picture1.FillColor = lColor
            Picture1.FillStyle = 0
            dStart = fStart * (CircleEnd / 100)
            dEnd = fEnd * (CircleEnd / 100)
            Picture1.Circle (100, 100), 60, , dStart, dEnd
          End Sub
    
          Private Sub Command1_Click()
            Picture1.ScaleMode = vbPixels
            Call DrawPiePiece(QBColor(1), 0.001, 36)
            Call DrawPiePiece(QBColor(2), 36, 55)
            Call DrawPiePiece(QBColor(3), 55, 75)
            Call DrawPiePiece(QBColor(4), 75, 99.999)
          End Sub
    
    

  5. Press the F5 key to run the project. You should see a pie chart being drawn with four sections mirroring the four times that the DrawPiece routine was called in the Command1_Click event.

REFERENCES

For more information, please see the following articles in the Microsoft Knowledge Base:

   ARTICLE-ID: Q83906
   TITLE     : How to Draw an Ellipse with Circle Statement in VB

   ARTICLE-ID: Q73280
   TITLE     : Overflow in VB Drawing Circle Segment w/ Radius of Zero

Instead of using the Circle method in the VBA language, you can also use the Win16/Win32 API Call to achieve the same result.
Keywords          : PrgOther VB4ALL VB4WIN vbwin GnrlVb kbgraphic kbprg
Technology        : kbvba
Version           : WINDOWS:4.0
Platform          : NT WINDOWS
Issue type        : kbhowto


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.