Excel) (Chart.GetChartElement 方法

返回有关指定 x 和 y 坐标处的图表元素的信息。 本方法的与众不同之处在于只需指定前两个参数的值。 Microsoft Excel 会填充其他参数,当该方法返回时,代码应检查这些值。

语法

表达式。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 21 AxisIndex AxisType
xlAxisTitle 17 AxisIndex AxisType
xlDisplayUnitLabel 30 AxisIndex AxisType
xlMajorGridlines 15 AxisIndex AxisType
xlMinorGridlines 16 AxisIndex AxisType
xlPivotChartDropZone 32 DropZoneType 无
xlPivotChartFieldButton 31 DropZoneType PivotFieldIndex
xlDownBars 20 GroupIndex 无
xlDropLines 26 GroupIndex None
xlHiLoLines 25 GroupIndex 无
xlRadarAxisLabels 27 GroupIndex 无
xlSeriesLines 22 GroupIndex 无
xlUpBars 18 GroupIndex 无
xlChartArea 2 无 无
xlChartTitle 4 无 无
xlCorners 6 无 无
xlDataTable 7 无 无
xlFloor 23 无 无
xlLeaderLines 29 无 无
xlLegend 24 无 无
xlNothing 28 无 无
xlPlotArea 19 无 无
xlWalls 5 无 无
xlDataLabel 7 SeriesIndex PointIndex
xlErrorBars 9 SeriesIndex 无
xlLegendEntry 12 SeriesIndex 无
xlLegendKey 13 SeriesIndex 无
xlSeries 3 SeriesIndex PointIndex
xlShape 14 ShapeIndex 无
xlTrendline 8 SeriesIndex TrendLineIndex
xlXErrorBars 10 SeriesIndex 无
xlYErrorBars 11 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 指定系列中的特定点的 点 集合中的偏移量。 值为 1 表示选中所有数据点。
SeriesIndex 指定一系列特定的 系列 集合中的偏移量。
ShapeIndex 指定某一特定形状的 Shapes 集合中的偏移量。
TrendlineIndex 指定 趋势线 集合在一系列内的特定趋势线中的偏移量。

示例

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

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

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。