Command1 Text1 Text2 Text3 Private Sub Command1_Click() Dim a As Single Dim b As Single Dim c As Single Dim s As Single a = Val(Text1.Text) b = Val(Text2.Text) c = Val(Text3.Text) s = a + b + c a = a / s b = b / s Call hb(a, b) End Sub Private Sub hb(ByVal a As Single, ByVal b As Single) pi = 3.14 Picture1.FillStyle = 0 For i = 0 To 200 Picture1.FillColor = vbRed Picture1.Circle (1500, 1500 - i), 1000, vbRed, -2 * pi, -2 * pi * a, 2 / 3 Picture1.FillColor = vbGreen Picture1.Circle (1500, 1500 - i), 1000, vbGreen, -2 * pi * a, -2 * pi * (a + b), 2 / 3 Picture1.FillColor = vbBlue Picture1.Circle (1500, 1500 - i), 1000, vbBlue, -2 * pi * (a + b), -2 * pi, 2 / 3 Next Picture1.FillColor = vbRed Picture1.Circle (1500, 1500 - i), 1000, vbWhite, -2 * pi, -2 * pi * a, 2 / 3 Picture1.FillColor = vbGreen Picture1.Circle (1500, 1500 - i), 1000, vbWhite, -2 * pi * a, -2 * pi * (a + b), 2 / 3 Picture1.FillColor = vbBlue Picture1.Circle (1500, 1500 - i), 1000, vbWhite, -2 * pi * (a + b), -2 * pi, 2 / 3 End Sub
www.wave12.com 图表组件wsChart4.0有平面和3D饼图示例代码可以参考
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 WithEnd Sub
参考: How To Label Pie Slices as Percentages in MSChart Pie Chart http://support.microsoft.com/default.aspx?scid=kb;en-us;230484
Private Sub Command1_Click()
Dim a As Single
Dim b As Single
Dim c As Single
Dim s As Single
a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
s = a + b + c
a = a / s
b = b / s
Call hb(a, b)
End Sub
Private Sub hb(ByVal a As Single, ByVal b As Single)
pi = 3.14
Picture1.FillStyle = 0
For i = 0 To 200
Picture1.FillColor = vbRed
Picture1.Circle (1500, 1500 - i), 1000, vbRed, -2 * pi, -2 * pi * a, 2 / 3
Picture1.FillColor = vbGreen
Picture1.Circle (1500, 1500 - i), 1000, vbGreen, -2 * pi * a, -2 * pi * (a + b), 2 / 3
Picture1.FillColor = vbBlue
Picture1.Circle (1500, 1500 - i), 1000, vbBlue, -2 * pi * (a + b), -2 * pi, 2 / 3
Next
Picture1.FillColor = vbRed
Picture1.Circle (1500, 1500 - i), 1000, vbWhite, -2 * pi, -2 * pi * a, 2 / 3
Picture1.FillColor = vbGreen
Picture1.Circle (1500, 1500 - i), 1000, vbWhite, -2 * pi * a, -2 * pi * (a + b), 2 / 3
Picture1.FillColor = vbBlue
Picture1.Circle (1500, 1500 - i), 1000, vbWhite, -2 * pi * (a + b), -2 * pi, 2 / 3
End Sub
.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 WithEnd Sub
How To Label Pie Slices as Percentages in MSChart Pie Chart
http://support.microsoft.com/default.aspx?scid=kb;en-us;230484