[英]Switch grouped axis on Excel chart
I have a chart of type xlColumnClustered
and I want to switch the x and y axis. 我有一个xlColumnClustered
类型的图表,我想切换x和y轴。 Problem is that the axis is grouped. 问题是轴是分组的。
My data looks like this: 我的数据如下:
Country Permenant Flat 1%
Appartment 0%
House 2%
Shaq 0%
Temporary Flat 2%
Appartment 9%
House 1%
Shaq 0%
State Permenant Flat 8%
Appartment 13%
House 30%
Shaq 5%
Temporary Flat 6%
Appartment 0%
House 2%
Shaq 0%
In ggplot
the command I would need is coord_flip(), it does this, does vba have any functionality similar to this?: 在ggplot
中我需要的命令是coord_flip(),它是这样做的,vba有没有类似的功能?:
My code currently looks like this: 我的代码目前看起来像这样:
Sub insert_housing()
Dim strRange As String
Dim rngChart As Range
Dim myChart As Chart
'Just grabbing the data, nothing to see here
sheet_name = "Sheet2"
With Sheets(sheet_name)
StartRow = .Range("D10000").End(xlUp).End(xlUp).Row
EndRow = .Range("D10000").End(xlUp).Row
End With
Sheets(sheet_name).Activate
Sheets(sheet_name).Range("$A$" & CStr(StartRow) & ":$D$" & CStr(EndRow)).Select
'Probably start reading here
Set myChart = ActiveSheet.Shapes.AddChart(xlColumnClustered).Chart
With myChart
.ChartArea.Format.TextFrame2.TextRange.Font.Size = 6
.HasTitle = True
.HasAxis(xlCategory, xlPrimary) = True
.ChartTitle.Text = "Frustrating Graphic of Housing"
.SeriesCollection(1).Name = "stuff"
.HasAxis(xlValue, xlPrimary) = True
.Axes(xlCategory, xlPrimary).CategoryType = xlAutomatic
End With
End Sub
So to be clear, I'd like to see the grouped x axis on the y axis, y axis on the x axis. 所以要清楚,我想看到y轴上的分组x轴,x轴上的y轴。
What have i tried? 我试过了什么?
Can anyone shed any light on how to put a grouped axis on the y axis in Excel VBA? 任何人都可以阐明如何在X V中将分组轴放在y轴上吗?
Can you not change chart type and use 2D plot? 你能改变图表类型并使用2D图吗?
This would yield: 这会产生:
Code recorded for this was: 为此记录的代码是:
ActiveSheet.Shapes.AddChart2(216, xlBarClustered).Select
ActiveChart.SetSourceData Source:=Range("Sheet6!$A$1:$D$16")
Which you can tidy into something like the following, to get rid of the .Select
你可以整理下面这样的东西,摆脱.Select
Dim c As Chart
Set c = ActiveSheet.Shapes.AddChart2(216, xlBarClustered).Chart
ActiveChart.SetSourceData Source:=Range("Sheet6!$A$1:$D$16")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.