ChartSheetBase.SetElement Method

Modifies an element on the chart that is displayed on the ChartSheetBase.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel.v4.0.Utilities (in Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)

Syntax

'Declaration
Public Sub SetElement ( _
    element As MsoChartElementType _
)
public void SetElement(
    MsoChartElementType element
)

Parameters

Remarks

Use the SetElement method to modify an element of the chart according to the options specified by the Microsoft.Office.Core.MsoChartElementType values. For example, to hide the table legend, pass the value Microsoft.Office.Core.MsoChartElementType.msoElementLegendNone to the SetElement method.

The operations you can perform by using this method correspond to the following buttons on the Layout tab of the Ribbon when a chart is selected:

  • All buttons in the Labels group.

  • All buttons in the Axes group.

  • All buttons in the Analysis group.

  • The Plot Area, Chart Wall, and Chart Floor buttons in the Background group.

Examples

The following code example applies the tenth layout that is available for the chart type of the chart in chart sheet Chart1. In addition, the example uses the SetElement method to apply further layout changes: setting the style of the chart title to be centered and to lie inside the chart grid area, adding a title for the horizontal axis, and adding a rotated title for the vertical axis. To run this code example, your workbook must contain a clustered column two-dimensional chart sheet named Chart1.

Private Sub DesignChartSheet()
    Dim myChartSheet As Microsoft.Office.Tools.Excel.ChartSheet = _
        Globals.Chart1.Base

    myChartSheet.ApplyLayout(10)

    myChartSheet.SetElement(Microsoft.Office.Core.MsoChartElementType. _
                       msoElementChartTitleCenteredOverlay)
    myChartSheet.SetElement(Microsoft.Office.Core.MsoChartElementType. _
                       msoElementPrimaryCategoryAxisTitleHorizontal)
    myChartSheet.SetElement(Microsoft.Office.Core.MsoChartElementType. _
                       msoElementPrimaryValueAxisTitleRotated)
End Sub
private void DesignChartSheet()
{
    Microsoft.Office.Tools.Excel.ChartSheet myChartSheet  =
        Globals.Chart1.Base;

    myChartSheet.ApplyLayout(10, myChartSheet.ChartType);

    myChartSheet.SetElement(Microsoft.Office.Core.MsoChartElementType.
                       msoElementChartTitleCenteredOverlay);
    myChartSheet.SetElement(Microsoft.Office.Core.MsoChartElementType.
                       msoElementPrimaryCategoryAxisTitleHorizontal);
    myChartSheet.SetElement(Microsoft.Office.Core.MsoChartElementType.
                       msoElementPrimaryValueAxisTitleRotated);
}

.NET Framework Security

See Also

Reference

ChartSheetBase Class

Microsoft.Office.Tools.Excel Namespace