Chart.SetElement 方法 (Project)

将指定的元素添加到图表或图表上的选定对象。

语法

expressionSetElement (RHS)

expression:一个表示 Chart 对象的变量。

参数

名称 必需/可选 数据类型 说明
RHS 必需 MsoChartElementType 要添加的图表元素类型的枚举常量之一。

返回值

Nothing

备注

SetElement 方法的 RHS 值对应于“添加图表元素”子列表中的项。 根据图表的类型,将启用不同的项。 如果尝试添加特定图表不存在的元素,则会收到未指定的错误。 例如,在 3D 图表上,“添加图表元素”下拉列表中的“误差线”项不可用。 对 的 Chart.SetElement msoElementErrorBarStandardDeviation 调用会导致错误。

示例

以下示例将次要网格线添加到数值轴,并将数据标签标注添加到第二个数据系列。

Sub TestSetElements()
    Dim chartShape As Shape
    Dim reportName As String
    
    reportName = "Simple 3D chart"
    Set chartShape = ActiveProject.Reports(reportName).Shapes(1)
    
    With chartShape.Chart
        .SetElement msoElementChartTitleAboveChart
        
        ' Select the major gridlines on the value axis, and then add minor gridlines.
        .axes(Office.xlValue).MajorGridlines.Select
        .SetElement msoElementPrimaryCategoryGridLinesMinor
        
        ' Select the second data series and add data label callouts.
        If .SeriesCollection.Count > 1 Then
            .SeriesCollection(2).Select
            .SetElement msoElementDataLabelCallout
        End If
    End With
End Sub

另请参阅

Chart 对象

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。