Chart.SetElement Method

Modifies an element on the chart.

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

Syntax

'Declaration
Sub SetElement ( _
    Element As MsoChartElementType _
)
void SetElement(
    MsoChartElementType Element
)

Parameters

  • Element
    Type: MsoChartElementType

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

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_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 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 Security

See Also

Reference

Chart Interface

Microsoft.Office.Tools.Excel Namespace