Partager via


Chart.SetElement(MsoChartElementType) Method

Definition

Modifies an element on the chart.

public:
 void SetElement(Microsoft::Office::Core::MsoChartElementType Element);
public void SetElement (Microsoft.Office.Core.MsoChartElementType Element);
abstract member 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_1 chart. 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, you must add a clustered column two-dimensional chart with the name Chart_1 to the default sheet Sheet1.

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

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