我有一个xlColumnClustered
类型的图表,我想切换x和y轴。问题是轴被分组。
我的数据如下:
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%
在ggplot
我需要的命令是coord_flip(),它是这样做的,vba有没有类似的功能?:
我的代码目前看起来像这样:
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
所以要清楚,我希望看到y轴上的分组x轴,x轴上的y轴。
我尝试了什么?
任何人都可以了解如何在yv轴上将分组轴放在Excel VBA中吗?
答案 0 :(得分:3)
你能改变图表类型并使用2D图吗?
这会产生:
为此记录的代码是:
ActiveSheet.Shapes.AddChart2(216, xlBarClustered).Select
ActiveChart.SetSourceData Source:=Range("Sheet6!$A$1:$D$16")
你可以整理下面的内容,以摆脱.Select
Dim c As Chart
Set c = ActiveSheet.Shapes.AddChart2(216, xlBarClustered).Chart
ActiveChart.SetSourceData Source:=Range("Sheet6!$A$1:$D$16")