How To Create Pie Charts Using the Circle Method in VB
Symptoms
The Pinnacle-BPS Graph control shipping with Visual Basic gives usersthe ability to create pie charts. The Pinnacle-BPS is a relatively largecontrol and uses a large amount of disk space on distribution disks.Therefore, the custom effects available are limited to the features of thecontrol. The Circle method in the VBA language provides functionality todraw arcs and segments. By drawing segments, you can easily create a piechart and add custom features as you require. Below is a code sampledemonstrating how to do this.
Resolution
Start a new Visual Basic project. Form1 is created by default.Place a Command button on the form.Place a 200×200 pixel Picture box on the form.Add the following code to the Form1 code window:
Option ExplicitPublic Sub DrawPiePiece(lColor As Long, fStart As Double, fEnd AsDouble)Const PI As Double = 3.14159265359Const CircleEnd As Double = -2 * PIDim dStart As DoubleDim dEnd As DoublePicture1.FillColor = lColorPicture1.FillStyle = 0dStart = fStart * (CircleEnd / 100)dEnd = fEnd * (CircleEnd / 100)Picture1.Circle (100, 100), 60, , dStart, dEndEnd SubPrivate Sub Command1_Click()Picture1.ScaleMode = vbPixelsCall 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 beingdrawn with four sections mirroring the four times that the DrawPieceroutine was called in the Command1_Click event.
