' 为Chart控件的各行各列赋值
MSChart.RowCount = 1
MSChart.ColumnCount = iMax + 1
MSChart.RowLabel = ""
For i = 0 To iMax
MSChart.Row = 1
MSChart.Column = i + 1
MSChart.Data = dataArray(i, 1)
MSChart.ColumnLabel = dataArray(i, 0)
Next
这段代码能画出漂亮的饼图来,但是,显示不出来个部分所占的百分比。
-----------------------------------------------------------------------------------------------------
MSChar显示百分比:
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
For i = 1 To .Plot.SeriesCollection.Count
With .Plot.SeriesCollection(i).DataPoints(-1).DataPointLabel
.LocationType = MSChart20Lib.VtChLabelLocationType.VtChLabelLocationTypeOutside
.LineStyle = MSChart20Lib.VtChLabelLineStyle.VtChLabelLineStyleBent
.Component = 2 'VtChLabelComponentPercent
.PercentFormat = "0%"
.VtFont.Size = 10
End With
Next i