Project) (Chart.GetChartElement 方法

返回有关指定 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 方法不返回任何内容。 返回的值位于 ElementID、 Arg1 和 Arg2 参数中。

备注

注意

GetChartElement 方法将在 Project 2013 的发布版本中删除。 Project 中的 图表 对象不实现事件;因此,无法通过与鼠标事件交互来使用 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

另请参阅

Chart 对象

支持和反馈

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