[英]Excel 2016 VBA Display every nth Data Label on Chart
I have a line chart that displays the revenue of multiple airlines, throughout the period of 2011 to 2016 - with data points plotted quarterly (Q1-Q4, for each year) on the X-axis我有一个折线图,显示了 2011 年至 2016 年期间多家航空公司的收入 - X 轴上每季度(Q1-Q4,每年)绘制数据点
I would like to only show the data labels (on the chart) for Q4 of each year, for each airline.我只想显示每个航空公司每年第四季度的数据标签(在图表上)。 I would like to do this and keep the axis as is.我想这样做并保持轴原样。
Any suggestions will be much appreciated,任何建议将不胜感激,
Thank you!谢谢! (I have Excel 2016) (我有 Excel 2016)
Your question didn't express clearly if you want to add the labels by means of a VBA macro.如果您想通过 VBA 宏添加标签,您的问题没有明确表达。 I suggest to do following:我建议做以下事情:
Dim sData as Series
For i = 1 to sData.Points.Count Step 4
sData.Points(i).ApplyDataLabels
Next i
Note that if there is not value for the Point i in the series, the label seems not to be displayed.请注意,如果系列中的点 i 没有值,则标签似乎不会显示。 It took a while to find out why a label was not added to the chart.花了一段时间才找出为什么没有将标签添加到图表中。 To detect this case, I wrote following test:为了检测这种情况,我编写了以下测试:
If sData.Points(i).HasDataLabel Then
If Len(sData.Points(i).DataLabel.Text) = 0 Then
...
End If
End IF
Searching a little in the web (around 3 minutes, that maybe you should spend the same time) found this article:在网上搜索了一下(大约 3 分钟,也许你应该花同样的时间)找到了这篇文章:
http://www.cs.mun.ca/~n39smm/Excel/Data%20Label.pdf http://www.cs.mun.ca/~n39smm/Excel/Data%20Label.pdf
This is the resume, but I suggest to view the document because have a lot of graphics.这是简历,但我建议查看文档,因为有很多图形。
A little research before asking can save you a lot of time.在询问之前进行一些研究可以为您节省大量时间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.