Compartir a través de


ChartSheetBase.SetElement(MsoChartElementType) Method

Definition

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

public:
 void SetElement(Microsoft::Office::Core::MsoChartElementType element);
public void SetElement (Microsoft.Office.Core.MsoChartElementType element);
member this.SetElement : Microsoft.Office.Core.MsoChartElementType -> unit
Public Sub SetElement (element As MsoChartElementType)

Parameters

element
MsoChartElementType

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

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 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);
}
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

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.

Applies to