Microsoft KB Archive/153927

= How To Create Pie Charts Using the Circle Method in VB =

Article ID: 153927

Article Last Modified on 7/15/2004

-

APPLIES TO


 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 16-bit Enterprise Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q153927



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
 Start a new Visual Basic project. Form1 is created by default. Place a Command button on the form. Place a 200x200 pixel Picture box on the form.  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  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.

