如何添加包含百分比的图表数据标签?

我想用Excel VBA默认添加图表数据标签。 这是我创build图表的代码:

Private Sub CommandButton2_Click() ActiveSheet.Shapes.AddChart.Select ActiveChart.SetSourceData Source:=Range("'Sheet1'!$A$6:$D$6") ActiveChart.ChartType = xlDoughnut End Sub 

它只创build没有信息标签的甜甜圈图表。

另外,当我想用​​这个相同的信息创build另一个图表types时,我怎样才能改变图表的坐标,使它不会看起来像覆盖同一个图表?

这里有一个方法使数据标签在%中:

  Private Sub CommandButton2_Click() Dim Cell As Range Set Cell = ActiveCell Set Myrange = Sheets("Sheet1").Range("$A$6:$D$6") ActiveSheet.Shapes.AddChart.Select ActiveChart.SetSourceData Source:=Myrange ActiveChart.ChartType = xlDoughnut With PlotArea ActiveChart.ApplyLayout (6) End With With ActiveChart .Legend.Delete '.ChartTitle.Delete '.ChartTitle.Text = "Here goes your tittle" End With With ActiveChart.SeriesCollection(1) .Points(1).Format.Fill.ForeColor.RGB = RGB(255, 0, 0) .Points(2).Format.Fill.ForeColor.RGB = RGB(255, 0, 0) .Points(3).Format.Fill.ForeColor.RGB = RGB(255, 0, 0) .Points(4).Format.Fill.ForeColor.RGB = RGB(255, 0, 0) End With With ActiveChart.Parent .Height = 200 ' resize .Width = 300 ' resize .Top = Cell.Top ' reposition .Left = Cell.Left ' reposition End With End Sub 

第二种types的图表:

 Private Sub CommandButton2_Click() Set MyRange = Sheets("Sheet1").Range("$A$6:$D$6") ActiveSheet.Shapes.AddChart.Select ActiveChart.SetSourceData Source:=MyRange ActiveChart.ChartType = xlColumnClustered With PlotArea ActiveChart.ApplyLayout (2) End With With ActiveChart .Legend.Delete '.ChartTitle.Delete '.ChartTitle.Text = "Here goes your tittle" End With With ActiveChart.SeriesCollection(1) .Points(1).Format.Fill.ForeColor.RGB = RGB(255, 0, 0) .Points(2).Format.Fill.ForeColor.RGB = RGB(255, 0, 0) .Points(3).Format.Fill.ForeColor.RGB = RGB(255, 0, 0) .Points(4).Format.Fill.ForeColor.RGB = RGB(255, 0, 0) End With With ActiveChart.Parent .Height = 200 ' resize .Width = 300 ' resize .Top = 300 ' reposition .Left = 300 ' reposition End With End Sub 

在这里你可以find颜色代码: http : //dmcritchie.mvps.org/excel/colors.htm