SetElement Method

ChartSheetBase.SetElement Method (MsoChartElementType)


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)

public void SetElement(
	MsoChartElementType element


Type: Microsoft.Office.Core.MsoChartElementType

One of the Microsoft.Office.Core.MsoChartElementType values that specifies the type of element modification.

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.

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 void DesignChartSheet()
    Microsoft.Office.Tools.Excel.ChartSheet myChartSheet  =

    myChartSheet.ApplyLayout(10, myChartSheet.ChartType);

Return to top
© 2016 Microsoft