修改图表中的元素。
命名空间:  Microsoft.Office.Tools.Excel
程序集:  Microsoft.Office.Tools.Excel(在 Microsoft.Office.Tools.Excel.dll 中)
语法
声明
Sub SetElement ( _
    Element As MsoChartElementType _
)
void SetElement(
    MsoChartElementType Element
)
参数
- Element
 类型:Microsoft.Office.Core.MsoChartElementType
 Microsoft.Office.Core.MsoChartElementType 值之一,指定元素修改的类型。
备注
使用 SetElement 方法可以根据 Microsoft.Office.Core.MsoChartElementType 值所指定的选项修改图表的元素。 例如,若要隐藏表格图例,可将值 Microsoft.Office.Core.MsoChartElementType.msoElementLegendNone 传递给 SetElement 方法。
使用此方法可以执行的操作与选择图表后功能区上**“布局”**选项卡上的下列按钮相对应:
- **“标签”**组中的所有按钮。 
- **“坐标轴”**组中的所有按钮。 
- **“分析”**组中的所有按钮。 
- “背景”组中的“绘图区”、**“背景墙”和“图表基底”**按钮。 
示例
下面的代码示例应用可供 Chart_1 图表的图表类型使用的第 10 个布局。 此外,该示例还使用 SetElement 方法应用更多布局更改:将图表标题的样式设置为居中且位于图表网格区域内,为水平轴添加标题,并为垂直轴添加旋转标题。 若要运行此代码示例,必须将名为 Chart_1 的二维簇状柱形图添加到默认的工作表 Sheet1 中。
Private Sub DesignChart()
    Dim myChart As Microsoft.Office.Tools.Excel.Chart = _
        Globals.Sheet1.Chart_1
    myChart.ApplyLayout(10)
    myChart.SetElement(Microsoft.Office.Core.MsoChartElementType. _
                       msoElementChartTitleCenteredOverlay)
    myChart.SetElement(Microsoft.Office.Core.MsoChartElementType. _
                       msoElementPrimaryCategoryAxisTitleHorizontal)
    myChart.SetElement(Microsoft.Office.Core.MsoChartElementType. _
                       msoElementPrimaryValueAxisTitleRotated)
End Sub
private void DesignChart()
{
    Microsoft.Office.Tools.Excel.Chart myChart =
        Globals.Sheet1.Chart_1;
    myChart.ApplyLayout(10, myChart.ChartType);
    myChart.SetElement(
        Microsoft.Office.Core.MsoChartElementType.
        msoElementChartTitleCenteredOverlay);
    myChart.SetElement(
        Microsoft.Office.Core.MsoChartElementType.
        msoElementPrimaryCategoryAxisTitleHorizontal);
    myChart.SetElement(
        Microsoft.Office.Core.MsoChartElementType.
        msoElementPrimaryValueAxisTitleRotated);
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。