HOWTO: Label Pie Slices as Percentages in MSChart Pie Chart

ID: Q230484


The information in this article applies to:
  • Microsoft Visual Basic Professional and Enterprise Editions for Windows, versions 5.0, 6.0


SUMMARY

When creating a Pie chart using the MSChart control, you might wish to label each "slice" of the pie as a percentage of the total. This article demonstrates how to do this.


MORE INFORMATION

The following example illustrates how to accomplish this task:

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


  2. From the Project menu, choose Components, check Microsoft Chart Control, and click OK.


  3. Add an instance of the MSChart control to Form1.


  4. Add the following code to Form1:


  5. 
       Private Sub Form_Load()
    
          With MSChart1
             .chartType = VtChChartType2dPie
    
          For i = 1 To 3
             .Row = 1
             .Column = i
             .Data = i * 100
          Next
        
          With .DataGrid
             .RowLabelCount = 1
             .ColumnCount = 3
             .RowCount = 1
             For i = 1 To .ColumnCount
                .ColumnLabel(i, 1) = "Column " & i
             Next i
             .RowLabel(1, 1) = "Data as a Percentage"
          End With
        
          For i = 1 To .Plot.SeriesCollection.Count
             With .Plot.SeriesCollection(i).DataPoints(-1).DataPointLabel
                .LocationType = VtChLabelLocationTypeOutside
                .Component = VtChLabelComponentPercent
                .PercentFormat = "0%"
                .VtFont.Size = 10
             End With
          Next i
    
          End With
       End Sub 
  6. Run the project.


Additional query words:

Keywords : kbCtrl kbVBp kbVBp500 kbVBp600 kbGrpVB
Version : WINDOWS:5.0,6.0
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: May 12, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.