返回有关指定 X 和 Y 坐标处的图表元素的信息。 将在 Project 2013 的已发布版本中删除此方法。
语法
表达式。GetChartElement (x、 y、 ElementID、 Arg1、 Arg2)
expression:一个表示 Chart 对象的变量。
参数
| 名称 | 必需/可选 | 数据类型 | 说明 |
|---|---|---|---|
| x | 必需 | Long | 图表元素的 X 坐标。 |
| y | 必需 | Long | 图表元素的 Y 坐标。 |
| ElementID | 必需 | Long | 当 GetChartElement 方法返回时,ElementID 包含指定坐标处图表元素的 Office.XLChartItem 值。 有关详细信息,请参阅备注。 |
| Arg1 | 必需 | Long | 当方法返回时, Arg1 包含与图表元素相关的信息。 有关详细信息,请参阅备注。 |
| Arg2 | 必需 | Long | 当方法返回时, Arg2 包含与图表元素相关的信息。 有关详细信息,请参阅备注。 |
返回值
GetChartElement 方法返回 Nothing。 返回的值位于 ElementID、 Arg1 和 Arg2 参数中。
备注
注意
Project 2013 的已发布版本中将删除 GetChartElement 方法。 Project 中的 Chart 对象不实现事件;因此,无法通过与鼠标事件交互,使用 GetChartElement 方法对 Project 中的图表进行动画处理。
GetChartElement 方法不常见,因为仅指定前两个参数的值。 Project 返回其他参数中的数据,当方法返回时,代码应检查这些值。
方法返回后的 ElementID 值确定 Arg1 和 Arg2 是否包含任何信息 (请参阅表 1) 。
表 1. 基于元素 ID 的 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 | 无 |
表 2 描述了方法返回后 Arg1 和 Arg2 的含义。 参数列中的值来自表 1。
表 2. Arg1 和 Arg2 中数据的含义
| 参数 | 说明 |
|---|---|
| AxisIndex | 指定轴主要或辅助。 可以是以下 Office.XlAxisGroup 常量之一: xlPrimary 或 xlSecondary。 |
| AxisType | 指定坐标轴类型。 可以是以下 Office.XlAxisType 常量之一: xlCategory、 xlSeriesAxis 或 xlValue。 |
| DropZoneType | 指定拖放区域类型: 列、 数据、 页或行字段。 可以是以下 Office.XlPivotFieldOrientation 常量之一: xlColumnField、 xlDataField、 xlPageField 或 xlRowField。 列和行字段常量分别指定系列和分类字段。 |
| GroupIndex | 指定特定图表组的 Office.IMsoChart.ChartGroups 集合中的偏移量。 |
| PivotFieldIndex | 指定特定列 (系列) 、数据、页面或行 (类别) 字段的 Excel.PivotFields 集合中的偏移量。 如果放置区域类型为 xlDataField,则值为 -1。 |
| PointIndex | 指定系列中特定点的 Office.IMsoSeries.Points 集合中的偏移量。 值 1 指示已选择所有数据点。 |
| SeriesIndex | 指定特定系列的 Office.IMsoChart.SeriesCollection 内的偏移量。 |
| ShapeIndex | 指定某一特定形状的 Shapes 集合中的偏移量。 |
| TrendlineIndex | 指定系列中特定趋势线的 Office.IMsoSeries.Trendlines 集合中的偏移量。 |
示例
以下示例获取图表中点 (100、 100) 的图表元素信息。 例如,如果点位于绘图区域内,则“即时”窗格中的输出为 idNum: 19, a: 0, b: 0。 从表 1 中的信息, xlPlotArea = 19。
Sub TestGetChartElements()
Dim chartShape As Shape
Dim reportName As String
Dim x As Long
Dim y As Long
Dim idNum As Long
Dim a As Long
Dim b As Long
reportName = "Simple scalar chart"
Set chartShape = ActiveProject.Reports(reportName).Shapes(1)
' Specify a point in the chart.
x = 100
y = 100
chartShape.Chart.GetChartElement x, y, idNum, a, b
Debug.Print "idNum: " & idNum & ", a: " & a & ", b: " & b
End Sub
另请参阅
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。