有没有办法在图表中的点添加标注标签,而不使用选择? [英] Is there a way to add a callout label to a point in a chart, without using select?

查看:315
本文介绍了有没有办法在图表中的点添加标注标签,而不使用选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在图表中的某个点添加标注标签,而不使用选择



记录宏,我得到这个:

  Sub Macro9()
ActiveSheet.ChartObjects(SPC)。激活
ActiveChart.FullSeriesCollection(1)。选择
ActiveChart.FullSeriesCollection(1).Points(4)。选择
ActiveChart.SetElement(msoElementDataLabelCallout)
End Sub

但我宁愿避免使用选择。我尝试在点上简单地使用 SetElement -method,但是失败了。使用


Is there a way to add a callout label to a point in a chart, without using Select?

Recording a macro, I got this:

Sub Macro9()
    ActiveSheet.ChartObjects("SPC").Activate
    ActiveChart.FullSeriesCollection(1).Select
    ActiveChart.FullSeriesCollection(1).Points(4).Select
    ActiveChart.SetElement (msoElementDataLabelCallout)
End Sub

But I would rather like to avoid using Select. I tried simply using the SetElement-method on the point, but that failed. Using the HasDataLabel = True-method simply adds a datalabel.

Is there any workarounds to selecting the point and then using SetElement on the chart, or will I have to settle for something resembling the above macro?

解决方案

Is this what you are trying? In the below code we have avoided .Activate/.Select completely :)

Feel free to play with .AutoShapeType property. You can also format the data label to show the values in whatever format you want.

Sub Sample()
    Dim objC As ChartObject, chrt As Chart, dl As DataLabel
    Dim p As Point

    Set objC = Sheet1.ChartObjects(1)
    Set chrt = objC.Chart
    Set p = chrt.FullSeriesCollection(1).Points(4)

    p.HasDataLabel = True

    Set dl = p.DataLabel

    With dl
        .Position = xlLabelPositionOutsideEnd
        .Format.AutoShapeType = msoShapeRectangularCallout
        .Format.Line.Visible = msoTrue
    End With
End Sub

Screenshot

这篇关于有没有办法在图表中的点添加标注标签,而不使用选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆