A pie segment is a wedge bounded by the intersection of an ellipse and two radials. The ellipse is drawn within an imaginary bounding rectangle. This class uses the Windows API Pie function to draw the pie segments.
|(Declarations)||Declarations||Declarations and private variables for the CGDIPie class.|
|BorderColor||Property||Get the current value of the color used to outline the pie segment.|
|BorderWidth||Property||Get the current value of the BorderWidth used to draw the pie.|
|Bottom||Property||Get the Bottom location of the bounding rectangle for the pie.|
|FillColor||Property||Get the current value of the color used to fill the pie segment.|
|Left||Property||Get the Left location of the bounding rectangle for the pie.|
|Right||Property||Get the Right location of the bounding rectangle for the pie.|
|Top||Property||Get the Top location of the bounding rectangle for the pie.|
|AddSlice||Method||Add a pie segment to the total value which is displayed when the DrawPieSlices method is called. Call this method repeatedly to add slices to a fully-formed pie chart. The class automatically calculates how big each slice should be based on the proportion of the value of this slice to the total of all of the slices. To draw the pie once the slices are added use DrawPieSlices. To reset pie data before creating a new pie, use ResetPieData.|
|DrawPieSlice||Method||Draw a slice of a pie on a selected device. The slice is drawn within an ellipse bounded by the dimensions of a rectangle specified in the Left, Top, Bottom and Right properties. The width of the outline of the pie slice is specified in the BorderWidth property. The color of the pie segment is specified in the FillColor property.|
|DrawPieSliceByAngle||Method||Draw a slice of a pie baed on the starting and ending angles. The slice is drawn within an ellipse bounded by the dimensions of a rectangle specified in the Left, Top, Bottom and Right properties. The width of the outline of the pie slice is specified in the BorderWidth property. The color of the pie segment is specified in the FillColor property.|
|DrawPieSliceByAngleSweep||Method||Draw a slice of a pie based on the starting angle and specified number of degrees. The slice is drawn within an ellipse bounded by the dimensions of a rectangle specified in the Left, Top, Bottom and Right properties. The width of the outline of the pie slice is specified in the BorderWidth property. The color of the pie segment is specified in the FillColor property.|
|DrawPieSlices||Method||Create a fully-drawn circle or ellipse with pie segments based on values added with the AddSlice method. The shape of the pie is determined by the bounding rectangle specified in the Left, Top, Bottom and Right properties.|
|ResetPieData||Method||Delete slice information that was previously added with the AddSlice method. Use this method if you want to create a new set of slices.|
|TranslateVBColor||Private||Translates VBA/VB6 color constants for system colors into GDI equivalents. VBA/VB6 color constants, such as vbRed, vbBlue, or values returned using the QBColor() or RGB() functions, can be used directly for the color values used with Windows API calls. However, the VBA/VB6 color constants for system colors (vbButtonFace, vb3DShadow etc.) do not map correctly to those expected by Windows. This function accepts either form of constant and translates the value, if necessary, into the equivalent value expected by the Windows GDI subsystem.|
' Example of the CGDIPie class ' ' To try this example, do the following: ' 1. Create a new form ' 2. Paste all the code from this example to the new form's module ' 3. Run the form and click on the background. Two sample pie charts are drawn onto the form Private Sub Form_Click() Dim GDIPie As CGDIPie Set GDIPie = New CGDIPie ' Erase the form background cls With GDIPie ' First draw a pie using the AddSlice/DrawPieSlices technique ' Size the pie to fit within the bounds of the form .Left = 10 .Top = 10 .Right = ScaleX(Me.ScaleWidth, vbTwips, vbPixels) - 10 .Bottom = ScaleY(Me.ScaleHeight, vbTwips, vbPixels) - 10 .BorderColor = vbBlack .BorderWidth = 1 ' Add values to the pie .AddSlice 300, vbBlue .AddSlice 20, vbRed .AddSlice 125, vbYellow .AddSlice 15, vbGreen .AddSlice 200, vbWhite ' Draw the slices. .DrawPieSlices Me.hDC .Left = 10 .Top = 10 .Right = 110 .Bottom = 110 ' Now draw a smaller pie by drawing the slices manually .BorderColor = vbBlue .BorderWidth = 1 .FillColor = vbYellow ' Draw a pie slice by specifying the radial end-points .BorderColor = vbBlue .DrawPieSlice Me.hDC, .Right, (.Bottom - .Top) * 0.5, .Left(.Right - .Left) * 0.8, .Top ' Draw a pie slice by specifying the angles .FillColor = vbRed .DrawPieSliceByAngle Me.hDC, 90, 180 ' Draw a pie slice by specifying the starting angle and an offset .BorderColor = vbBlue .FillColor = vbMagenta .DrawPieSliceByAngleSweep Me.hDC, 180, 90 End With End Sub
The source code in Total Visual Sourcebook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.
Total Visual SourceBook is written for the needs of a developer using a source code library covering the many challenges you face. Countless developers over the years have told us they learned some or much of their development skills and tricks from our code. You can too!
Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!
"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."
Van T. Dinh, Microsoft MVP