我在互联网上找到了这个代码,用于将图例中的名称添加到图表中系列的点上。我的问题一直是试图旋转标签,使其旋转90度。有人知道如何将orientation属性合并到这段代码中吗?
谢谢
Dim mySrs As Series
Dim nPts As Long
For Each mySrs In ActiveChart.SeriesCollection
With mySrs
nPts = .Points.Count
mySrs.Points(nPts).ApplyDataLabels _
Type:=xlDataLabelsShowValue, _
AutoText:=True, LegendKey:=False
mySrs.Points(nPts).DataLabel.Text = mySrs.Name
End With
Next
答案 0 :(得分:1)
Point
个对象有DataLabel
个成员。每个DataLabel
都有一个名为orientation
的成员。根据{{3}}
此属性的值可以设置为-90到90度的整数值,也可以设置为以下常量之一:
xlDownward
xlHorizontal
xlUpward
xlVertical
所以解决你的问题的方法很简单:
mySrs.Points(nPts).DataLabel.Orientation = 90
应该简单:)
答案 1 :(得分:0)
这对我有用,
Dim cht As Chart
Set cht = Sheets("MySheet").Shapes.AddChart2.Chart
Dim rng As Range
cht.SetSourceData Source:=Range("MySheet!B3:G3")
'Many other chart formatting options...
cht.FullSeriesCollection(1).Select
cht.FullSeriesCollection(1).ApplyDataLabels
cht.FullSeriesCollection(1).DataLabels.Select
Selection.Orientation = xlUpward
Selection.Format.TextFrame2.Orientation = msoTextOrientationUpward
'In my case this will put the labels in the middle of the bars
Selection.Position = xlLabelPositionCenter
' From here it is just more formatting
With Selection.Format.TextFrame2.TextRange.Font.Fill
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorBackground1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0
.Transparency = 0
.Solid
End With