ChartSheet.GetChartElement Method (2007 System)

Gets information about the chart element at specified X and Y coordinates.

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

Syntax

'Declaration
Public Sub GetChartElement ( _
    x As Integer, _
    y As Integer, _
    ByRef ElementID As Integer, _
    ByRef Arg1 As Integer, _
    ByRef Arg2 As Integer _
)
'Usage
Dim instance As ChartSheet 
Dim x As Integer 
Dim y As Integer 
Dim ElementID As Integer 
Dim Arg1 As Integer 
Dim Arg2 As Integer

instance.GetChartElement(x, y, ElementID, _
    Arg1, Arg2)
public void GetChartElement(
    int x,
    int y,
    ref int ElementID,
    ref int Arg1,
    ref int Arg2
)
public:
void GetChartElement(
    int x, 
    int y, 
    int% ElementID, 
    int% Arg1, 
    int% Arg2
)
public function GetChartElement(
    x : int, 
    y : int, 
    ElementID : int, 
    Arg1 : int, 
    Arg2 : int
)

Parameters

  • x
    Type: System.Int32

    The X coordinate of the chart element.

  • y
    Type: System.Int32

    The Y coordinate of the chart element.

  • ElementID
    Type: System.Int32%

    When the method returns, this argument contains the XlChartItem value of the chart element at the specified coordinates. For more information, see the "Remarks" section.

  • Arg1
    Type: System.Int32%

    When the method returns, this argument contains information related to the chart element. For more information, see the "Remarks" section.

  • Arg2
    Type: System.Int32%

    When the method returns, this argument contains information related to the chart element. For more information, see the "Remarks" section.

Remarks

This method is unusual in that you specify values for only the first two arguments. Microsoft Office Excel fills in the other arguments, and your code should examine those values when the method returns.

The value of ElementID after the method returns determines whether Arg1 and Arg2 contain any information, as shown in the following table.

ElementID

Arg1

Arg2

xlAxis

AxisIndex

AxisType

xlAxisTitle

AxisIndex

AxisType

xlDisplayUnitLabel

AxisIndex

AxisType

xlMajorGridlines

AxisIndex

AxisType

xlMinorGridlines

AxisIndex

AxisType

xlPivotChartDropZone

DropZoneType

None

xlPivotChartFieldButton

DropZoneType

PivotFieldIndex

xlDownBars

GroupIndex

None

xlDropLines

GroupIndex

None

xlHiLoLines

GroupIndex

None

xlRadarAxisLabels

GroupIndex

None

xlSeriesLines

GroupIndex

None

xlUpBars

GroupIndex

None

xlChartArea

None

None

xlChartTitle

None

None

xlCorners

None

None

xlDataTable

None

None

xlFloor

None

None

xlLegend

None

None

xlNothing

None

None

xlPlotArea

None

None

xlWalls

None

None

xlDataLabel

SeriesIndex

PointIndex

xlErrorBars

SeriesIndex

None

xlLegendEntry

SeriesIndex

None

xlLegendKey

SeriesIndex

None

xlSeries

SeriesIndex

PointIndex

xlShape

ShapeIndex

None

xlTrendline

SeriesIndex

TrendLineIndex

xlXErrorBars

SeriesIndex

None

xlYErrorBars

SeriesIndex

None

The following table describes the meaning of Arg1 and Arg2 after the method returns.

Argument

Description

AxisIndex

Specifies whether the axis is primary or secondary. Can be one of the following XlAxisGroup constants: xlPrimary or xlSecondary.

AxisType

Specifies the axis type. Can be one of the following XlAxisType constants: xlCategory, xlSeriesAxis, or xlValue.

DropZoneType

Specifies the drop zone type: column, data, page, or row field. Can be one of the following XlPivotFieldOrientation constants: xlColumnField, xlDataField, xlPageField, or xlRowField. The column and row field constants specify the series and category fields, respectively.

GroupIndex

Specifies the offset within the ChartGroups collection for a specific chart group.

PivotFieldIndex

Specifies the offset within the T:Microsoft.Office.Interop.Excel.PivotFields collection for a specific column (series), data, page, or row (category) field. -1 if the drop zone type is xlDataField.

PointIndex

Specifies the offset within the Points collection for a specific point within a series. A value of – 1 indicates that all data points are selected.

SeriesIndex

Specifies the offset within the Series collection for a specific series.

ShapeIndex

Specifies the offset within the Shapes collection for a specific shape.

TrendlineIndex

Specifies the offset within the Trendlines collection for a specific trendline within a series.

Usage Requirements

GetChartElement does not work when the ExcelLocale1033Attribute attribute in your project is set to true (the default). If the ExcelLocale1033Attribute attribute is true, you must perform the following steps:

  • You must call the GetChartElement method of the underlying Chart, instead of the Microsoft.Office.Tools.Excel.ChartSheet host item.

  • You must use the Unwrap method on the underlying Chart object before calling GetChartElement.

    Unwrap modifies this object so that it passes the locale ID of the current thread to the Excel object model, instead of passing locale ID 1033.

The code example in this topic shows how to use GetChartElement when the ExcelLocale1033Attribute attribute is true. For more information about ExcelLocale1033Attribute and the Unwrap method, see Formatting Data in Excel with Various Regional Settings.

Examples

The following code example uses the GetChartElement method to display the chart element when a user clicks the chart.

Note

This example assumes that the ExcelLocale1033Attribute attribute is true (the default). If the ExcelLocale1033Attribute attribute is false, you can call the GetChartElement method of the Microsoft.Office.Tools.Excel.ChartSheet host item, and you do not need to use the Unwrap method. For more information, see the Remarks section in this topic.

Private Sub DisplayChartElement()
    Globals.Sheet1.Range("A1", "A5").Value2 = 22
    Globals.Sheet1.Range("B1", "B5").Value2 = 55

    Me.SetSourceData(Globals.Sheet1.Range("A1", "B5"), _
        Excel.XlRowCol.xlColumns)
    Me.ChartType = Excel.XlChartType.xlColumnClustered
End Sub 

Sub ChartSheet_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, _
    ByVal x As Integer, ByVal y As Integer) Handles Me.MouseDown

    Dim elementID As Integer = 0
    Dim arg1 As Integer = 0
    Dim arg2 As Integer = 0

    Dim innerChart As Excel.Chart = CType( _
        Microsoft.Office.Tools.Excel.ExcelLocale1033Proxy.Unwrap( _
        Me.InnerObject), Excel.Chart)

    innerChart.GetChartElement(x, y, elementID, arg1, arg2)

    MsgBox("Chart element is: " & CType(elementID, Excel.XlChartItem).ToString() _
            & Constants.vbNewLine & "arg1 is: " & arg1.ToString() _
            & Constants.vbNewLine & "arg2 is: " & arg2.ToString())
End Sub
private void DisplayChartElement()
{
    Globals.Sheet1.Range["A1", "A5"].Value2 = 22;
    Globals.Sheet1.Range["B1", "B5"].Value2 = 55;

    this.SetSourceData(Globals.Sheet1.Range["A1", "B5"],
        Excel.XlRowCol.xlColumns);
    this.ChartType = Excel.XlChartType.xlColumnClustered;

    this.MouseDown +=
        new Excel.ChartEvents_MouseDownEventHandler(ChartSheet_MouseDown);
}

void ChartSheet_MouseDown(int Button, int Shift, int x, int y)
{
    Int32 elementID = 0;
    Int32 arg1 = 0;
    Int32 arg2 = 0;

    Excel.Chart innerChart = (Excel.Chart)Microsoft.Office.Tools.
        Excel.ExcelLocale1033Proxy.Unwrap(this.InnerObject);

    innerChart.GetChartElement(x, y, ref elementID, ref arg1, ref arg2);

    MessageBox.Show("Chart element is: " + ((Excel.XlChartItem)elementID).ToString()
        + "\n arg1 is: " + arg1.ToString() + "\n arg2 is: " + arg2.ToString());
}

.NET Framework Security

See Also

Reference

ChartSheet Class

ChartSheet Members

Microsoft.Office.Tools.Excel Namespace