vba 使用excel VBA更改图表和图例的方向
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22827551/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change orientation of chart and legend using excel VBA
提问by yoshiserry
For some reason if there is less than four rows of data and you try and scatter chart it the cluster (column A) is shown on the legend, but if more than 4 rows of data exist then the other columns (A, B, C) are on the legend (Y axis).
出于某种原因,如果数据少于四行并且您尝试对其进行散点图,则图例上会显示集群(A 列),但如果存在超过 4 行的数据,则其他列(A、B、C ) 位于图例(Y 轴)上。
Can you please show me using VBA how do I re orientate this graph to look like graph (2)?
你能用 VBA 告诉我如何重新定位这个图,使其看起来像图(2)吗?
I need to reorient the legend series to be on the horizontal category axis using VBA(since the macro recorder doesn't show how to do this.
我需要使用 VBA 将图例系列重新定向到水平类别轴上(因为宏记录器未显示如何执行此操作。
GRAPH 1 STARTS OFF LOOKING LIKE THIS
图 1 开始看起来像这样
GRAPH 2 THIS IS HOW I DO IT MANUALLY
图 2 这是我手动操作的方式
(reorient legend entries - left, and category labels - right)
(重新定位图例条目 - 左侧,和类别标签 - 右侧)
GRAPH 3 The scatterchart dialog ends up looking like this, which is what I want to do in VBA
GRAPH 3 散点图对话框最终看起来像这样,这就是我想在 VBA 中做的
GRAPH 4 Final Graph looks like this, This is what I want to achieve in VBA
GRAPH 4 Final Graph 看起来是这样的,这就是我想在 VBA 中实现的
Lastly this is what the macro recorder creates, but when I try and run it, its missing, the range and Plotby parameters and fails
最后,这是宏记录器创建的内容,但是当我尝试运行它时,它丢失了范围和 Plotby 参数并失败了
Range("A1:D3").Select
Range("D3").Activate
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlXYScatter
ActiveChart.SetSourceData
回答by Mitja Bezen?ek
Your columns and rows are reversed. When you have the chart selected go und "Design" contextual tab and click "Switch Row/Column". Does that fix it? If yes you can use:
你的列和行是颠倒的。选择图表后,转到“设计”上下文选项卡,然后单击“切换行/列”。那能解决吗?如果是,您可以使用:
ActiveChart.PlotBy = xlRows or ActiveChart.PlotBy = xlColumns
to do it programatically.
以编程方式执行此操作。