畫餅圖所需要的數據都在數組裏面:
dim dataArray(0 to iMax, 0 to 1)
其中dataArray(i,0)是標題
dataArray(i,0)是數字
代碼如下:
MSChart.chartType = VtChChartType2dPie ' 畫餅圖
MSChart.Visible = True
MSChart.AllowSelections = False
MSChart.ShowLegend = True
MSChart.TitleText = "百分比圖"
' 爲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
End With
End Sub