GetChartElement 方法

       

返回指定的 X 坐标和 Y 坐标上图表元素的信息。本方法稍有与众不同之处:调用时只须指定前两个参数,在本方法执行期间,Microsoft Excel 为其余参数赋值,本方法返回后应检验这些参数的值。

expression.GetChartElement(X, Y, ElementID, Arg1, Arg2)

expression   必需。该表达式返回一个 Chart 对象。

X   Long 类型,必需。图表元素的 X 坐标。

Y   Long 类型,必需。图表元素的 Y 坐标。

ElementID   Long 类型,必需。本方法返回后,本参数包含指定坐标的图表元素的 XLChartItem 值。有关详细信息,请参阅“说明”部分。

Arg1   Long 类型,必需。本方法返回后,本参数包含与图表元素相关的信息。有关详细信息,请参阅“说明”部分。

Arg2   Long 类型,必需。本方法返回后,本参数包含与图表元素相关的信息。有关详细信息,请参阅“说明”部分。

说明

本方法返回的 ElementID 值决定了 Arg1Arg2 所包含的信息,如下表所示。

ElementID Arg1 Arg2
xlAxis AxisIndex AxisType
xlAxisTitle AxisIndex AxisType
xlDisplayUnitLabel AxisIndex AxisType
xlMajorGridlines AxisIndex AxisType
xlMinorGridlines AxisIndex AxisType
xlPivotChartDropZone DropZoneType
xlPivotChartFieldButton DropZoneType PivotFieldIndex
xlDownBars GroupIndex
xlDropLines GroupIndex
xlHiLoLines GroupIndex
xlRadarAxisLabels GroupIndex
xlSeriesLines GroupIndex
xlUpBars GroupIndex
xlChartArea
xlChartTitle
xlCorners
xlDataTable
xlFloor
xlLegend
xlNothing
xlPlotArea
xlWalls
xlDataLabel SeriesIndex PointIndex
xlErrorBars SeriesIndex
xlLegendEntry SeriesIndex
xlLegendKey SeriesIndex
xlSeries SeriesIndex PointIndex
xlShape ShapeIndex
xlTrendline SeriesIndex TrendLineIndex
xlXErrorBars SeriesIndex
xlYErrorBars SeriesIndex

下表说明了本方法返回后,参数 Arg1Arg2 的含义。

参数 说明
AxisIndex 指定坐标轴是主坐标轴还是次坐标轴。可为以下 XlAxisGroup 常量之一:xlPrimaryxlSecondary
AxisType 指定坐标轴类型。可为以下 XlAxisType 常量之一:xlCategoryxlSeriesAxisxlValue
DropZoneType 指定放置区的类型:列、数据、页或行字段。可为以下 XlPivotFieldOrientation 常量之一:xlColumnFieldxlDataFieldxlPageFieldxlRowField。列和行字段常量分别指定了数据系列和分类字段。
GroupIndex 指定特定图表组在 ChartGroups 集合中的偏移量。
PivotFieldIndex 指定特定的列(数据系列)、数据、页或行(分类)字段在 PivotFields 集合中的偏移量。如果放置区域类型为 xlDataField,则返回 -1。
PointIndex 表示系列中指定点在 Points 集合内的偏移量。– 1 表示选定了所有数据点。
SeriesIndex 指定特定系列在 Series 集合中的偏移量。
ShapeIndex 指定特定图形在 Shapes 集合中的偏移量。
TrendlineIndex 指定某个数据系列中特定趋势线在 Trendlines 集合中的偏移量。

示例

当鼠标移动到图表图例上时,本示例发出警告。

Private Sub Chart_MouseMove(ByVal Button As Long, _
        ByVal Shift As Long, ByVal X As Long, ByVal Y As Long)
    Dim IDNum As Long
    Dim a As Long
    Dim b As Long
    
    ActiveChart.GetChartElement X, Y, IDNum, a, b
    If IDNum = xlLegendEntry Then _
        MsgBox "WARNING: Move away from the legend"
End Sub