获取有关指定 X 和 Y 坐标上的图表元素的信息。
命名空间:  Microsoft.Office.Tools.Excel
程序集:  Microsoft.Office.Tools.Excel.v4.0.Utilities(在 Microsoft.Office.Tools.Excel.v4.0.Utilities.dll 中)
语法
声明
Public Sub GetChartElement ( _
    x As Integer, _
    y As Integer, _
    ByRef elementID As Integer, _
    ByRef arg1 As Integer, _
    ByRef arg2 As Integer _
)
public void GetChartElement(
    int x,
    int y,
    ref int elementID,
    ref int arg1,
    ref int arg2
)
参数
- x
 类型:System.Int32
 图表元素的 X 坐标。
- y
 类型:System.Int32
 图表元素的 Y 坐标。
- elementID
 类型:System.Int32%
 该方法返回时,此参数包含指定坐标上的图表元素的 XlChartItem 值。有关更多信息,请参见“备注”部分。
- arg1
 类型:System.Int32%
 该方法返回时,此参数包含与图表元素有关的信息。有关更多信息,请参见“备注”部分。
- arg2
 类型:System.Int32%
 该方法返回时,此参数包含与图表元素有关的信息。有关更多信息,请参见“备注”部分。
备注
此方法比较特殊,因为只需指定前两个参数的值。 Microsoft Office Excel 会填充其他参数,您的代码应在该方法返回时检查这些值。
该方法返回后的 ElementID 值确定 Arg1 和 Arg2 是否包含如下表中所示的信息。
| ElementID | Arg1 | Arg2 | 
|---|---|---|
| AxisIndex | AxisType | |
| AxisIndex | AxisType | |
| AxisIndex | AxisType | |
| AxisIndex | AxisType | |
| AxisIndex | AxisType | |
| DropZoneType | 无 | |
| DropZoneType | PivotFieldIndex | |
| GroupIndex | 无 | |
| GroupIndex | 无 | |
| GroupIndex | 无 | |
| GroupIndex | 无 | |
| GroupIndex | 无 | |
| GroupIndex | 无 | |
| 无 | 无 | |
| 无 | 无 | |
| 无 | 无 | |
| 无 | 无 | |
| 无 | 无 | |
| 无 | 无 | |
| 无 | 无 | |
| 无 | 无 | |
| 无 | 无 | |
| 无 | 无 | |
| SeriesIndex | PointIndex | |
| SeriesIndex | 无 | |
| SeriesIndex | 无 | |
| SeriesIndex | 无 | |
| SeriesIndex | PointIndex | |
| ShapeIndex | 无 | |
| SeriesIndex | TrendLineIndex | |
| SeriesIndex | 无 | |
| SeriesIndex | 无 | 
下表说明了该方法返回后的 Arg1 和 Arg2 的含义。
| 参数 | 说明 | 
|---|---|
| AxisIndex | 指定轴是主轴或还是辅助轴。 可以是下列 XlAxisGroup 常数之一:xlPrimary 或 xlSecondary。 | 
| AxisType | 指定轴类型。 可以为以下 XlAxisType 常数之一:xlCategory、xlSeriesAxis 或 xlValue。 | 
| DropZoneType | 指定拖放区域类型:列、数据、页或行字段。 可以为以下 XlPivotFieldOrientation 常数之一:xlColumnField、xlDataField、xlPageField 或 xlRowField。 列和行字段常数分别指定系列和类别字段。 | 
| GroupIndex | 指定特定图表组在 Microsoft.Office.Interop.Excel.ChartGroups 集合中的偏移量。 | 
| PivotFieldIndex | 指定特定列(系列)、数据、页或行(类别)字段在 T:Microsoft.Office.Interop.Excel.PivotFields 集合中的偏移量。 如果拖放区域类型为 xlDataField,则为 -1。 | 
| PointIndex | 指定系列中的特定点在 Points 集合中的偏移量。 该值为 – 1 时指示选择了所有数据点。 | 
| SeriesIndex | 指定特定系列在 Series 集合中的偏移量。 | 
| ShapeIndex | 指定特定形状在 Shapes 集合中的偏移量。 | 
| TrendlineIndex | 指定系列中的特定趋势线在 Trendlines 集合中的偏移量。 | 
示例
下面的代码示例使用 GetChartElement 方法在用户单击图表时显示图表元素。
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
    Me.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;
    this.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 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。