【发布时间】:2018-03-27 08:20:22
【问题描述】:
我目前在 Excel 中创建箱线图时遇到问题
temp.Activate
With ActiveSheet
'First diagram
.Shapes.AddChart2(227, xlLine).Select
With ActiveChart
.SetSourceData Source:=ActiveSheet.Range(ActiveSheet.Cells(2, 1), ActiveSheet.Cells(pEnd, 15))
.ChartTitle.Text = "Diagram 1"
.Axes(xlValue).MinimumScale = -30
.Axes(xlValue).MaximumScale = 25
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Axe1"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Axe2"
.Axes(xlValue).Crosses = xlMaximum
.HasLegend = True
ActiveSheet.Shapes(ActiveChart.Parent.Name).ScaleWidth 3, msoFalse, msoScaleFromTopLeft
ActiveSheet.Shapes(ActiveChart.Parent.Name).ScaleHeight 2, msoFalse, msoScaleFromTopLeft
.ClearToMatchStyle
.ChartStyle = 230
End With
.Shapes.AddChart2(408, xlBoxwhisker, 200, 100, 350, 200, True).Select
With ActiveChart
.SetSourceData Source:=ActiveSheet.Range(ActiveSheet.Cells(2, 1), ActiveSheet.Cells(pEnd, 15))
.ChartTitle.Text = "Diagram 2"
.HasLegend = True
ActiveSheet.Shapes(ActiveChart.Parent.Name).ScaleWidth 3, msoFalse, msoScaleFromTopLeft
ActiveSheet.Shapes(ActiveChart.Parent.Name).ScaleHeight 2, msoFalse, msoScaleFromTopLeft
End With 'Chart
End With 'temp
第一个图表的创建没有任何问题。对于第二个图表,Excel 报错:“对象不支持此操作。”
上线:
.SetSourceData Source:=ActiveSheet.Range(ActiveSheet.Cells(2, 1),
ActiveSheet.Cells(pEnd, 15))
这是 BoxWhisker 图的问题吗?还是我合并了一个错误
谢谢!
最好的问候, 蒂莫
【问题讨论】:
-
您能否说明一小部分输入数据的预期输出?您可以使用table generator 格式化数据,然后在代码标签之间添加。
-
@QHarr 我可以做到。我很惊讶代码不起作用,因为我用 Excel 记录了它
-
欢迎来到宏记录器的世界!恐怕这可能发生在宏录制的代码中。这并不罕见。
-
|测试1 | 2 | -3 | 1 | 2 | |:-----:|---|----|----|----| |测试2 | 3 | -4 | -2 | -1 | |测试3 | 5 | 6 | 4 | 2 |
-
@QHarr 它应该是这样的:boxplot