【发布时间】:2017-07-11 09:01:19
【问题描述】:
我正在从堆积柱形图制作箱线图,并使用减号和加号误差线来形成我的箱线图的胡须。 i referred to this to create a boxplot in Excel 2010
创建正方向误差条的代码
.SeriesCollection(4).ErrorBar Direction:=xlY, Include:= _
xlPlusValues, Type:=xlCustom, Amount:="=Sheet3!$B$12:$G$12"
有效但负方向错误栏:
.SeriesCollection(2).ErrorBar Direction:=xlY, Include:= _
xlMinusValues, Type:=xlCustom, Amount:="=Sheet3!$B$9:$G$9"
抛出Runtime error '13': Type mismatch
这是完整的代码:
Sub boxplot()
Dim rng As Range
Dim cht As Chart
Set datasht = ThisWorkbook.Sheets(3)
Set rng = getChtrng(8, 12, 2, 7) 'select cell ranges to populate chart
datasht.Activate
rng.Select
Set cht = charts.Add
Set cht = cht.Location(Where:=xlLocationAsObject, Name:="Sheet3")
With cht
.SetSourceData rng
.ChartType = xlColumnStacked
.SeriesCollection(1).XValues = "=Sheet3!$B$1:$G$1"
.HasTitle = True
.HasLegend = False
.ChartTitle.Text = ThisWorkbook.Sheets(1).Cells(1, 6).Value
'remove min, q1 and max quartile bars
.SeriesCollection(1).Select
Selection.Format.Fill.Visible = msoFalse
.SeriesCollection(2).Select
Selection.Format.Fill.Visible = msoFalse
.SeriesCollection(5).Select
Selection.Format.Fill.Visible = msoFalse
'include top whisker
.SeriesCollection(4).ErrorBar Direction:=xlY, Include:= _
xlPlusValues, Type:=xlCustom, Amount:="=Sheet3!$B$12:$G$12"
'include bottom whisker
.SeriesCollection(2).ErrorBar Direction:=xlY, Include:= _
xlMinusValues, Type:=xlCustom, Amount:="=Sheet3!$B$9:$G$9"
End With
End Sub
另外,在 vba 中创建箱线图的任何替代方法肯定有效?
【问题讨论】:
-
我没有经常使用图表来确定,但是你的问题是否有理由说你为
SeriesCollection(4)设置了xlMinusValues,但你的代码显示你为SeriesCollection(2)设置了它? -
对不起,我只是在试验这些值
标签: vba excel boxplot errorbar