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 值决定了 Arg1 和 Arg2 所包含的信息,如下表所示。

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 无

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

参数 说明
AxisIndex 指定坐标轴是主坐标轴还是次坐标轴。可为以下 XlAxisGroup 常量之一:xlPrimary 或 xlSecondary。
AxisType 指定坐标轴类型。可为以下 XlAxisType 常量之一:xlCategory、xlSeriesAxis 或 xlValue。
DropZoneType 指定放置区的类型:列、数据、页或行字段。可为以下 XlPivotFieldOrientation 常量之一:xlColumnField、xlDataField、xlPageField 或 xlRowField。列和行字段常量分别指定了数据系列和分类字段。
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