ChartSheetBase.GetChartElement(Int32, Int32, Int32, Int32, Int32) 方法

定义

获取有关指定 X 和 Y 坐标上的图表元素的信息。

public void GetChartElement (int x, int y, ref int elementID, ref int arg1, ref int arg2);

参数

x
Int32

图表元素的 X 坐标。

y
Int32

图表元素的 Y 坐标。

elementID
Int32

该方法返回时,此参数包含指定坐标上的图表元素的 XlChartItem 值。 有关更多信息,请参见“备注”部分。

arg1
Int32

该方法返回时,此参数包含与图表元素有关的信息。 有关更多信息,请参见“备注”部分。

arg2
Int32

该方法返回时,此参数包含与图表元素有关的信息。 有关更多信息,请参见“备注”部分。

示例

下面的代码示例使用 GetChartElement 方法在用户单击图表时显示图表元素。

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

注解

此方法在不常见的情况下,只为前两个参数指定值。 Microsoft Office Excel 将填充其他参数,并且在该方法返回时,代码应检查这些值。

在方法返回后,的值将 ElementID 确定 Arg1 和是否 Arg2 包含任何信息,如下表所示。

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
xlLeaderLines 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

下表描述了 Arg1 Arg2 方法返回后和的含义。

参数 描述
AxisIndex 指定轴是 "主要" 还是 "辅助"。 可以是下列 XlAxisGroup 常数之一:xlPrimaryxlSecondary
AxisType 指定轴类型。 可以为以下 XlAxisType 常数之一:xlCategoryxlSeriesAxisxlValue
DropZoneType 指定放置区类型:列、数据、页或行字段。 可以是下列 XlPivotFieldOrientation 常量之一: xlColumnFieldxlDataFieldxlPageFieldxlRowField 。 列和行字段常量分别指定序列和类别字段。
GroupIndex 指定特定图表组在集合内的偏移量 Microsoft.Office.Interop.Excel.ChartGroups
PivotFieldIndex 在 T:Microsoft.Office.Interop.Excel.PivotFields 集合中指定特定列(序列)、数据、页或行(类别)字段的偏移量。 如果放置区类型为,则为-1 xlDataField
PointIndex Points为序列中的特定点指定集合内的偏移量。 值–1指示选择所有数据点。
SeriesIndex 指定特定序列的集合内的偏移量 Series
ShapeIndex 指定特定形状在集合内的偏移量 Shapes
TrendlineIndex Trendlines为序列中的特定趋势指定集合内的偏移量。

适用于