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 包含與 chart 元素相關的資訊。 如需詳細資訊,請參閱 備註。
Arg2 必要 Long 當方法傳回時, Arg2 會包含與 chart 元素相關的資訊。 如需詳細資訊,請參閱 備註。

傳回值

GetChartElement 方法不會傳回任何內容。 傳回值位於 ElementID、 Arg1 和 Arg2 參數中。

註解

注意事項

GetChartElement 方法將在 Project 2013 發行版本中移除。 Project 中的 Chart 物件不會實作事件;因此,Project 中的圖表無法透過與滑鼠事件互動,以使用 GetChartElement 方法製作動畫。

GetChartElement 方法很不尋常,因為您只指定前兩個引數的值。 Project 會在其他引數中傳回資料,而您的程式碼應在方法傳回時檢查這些值。

方法傳回之後的 ElementID 值決定 Arg1 和 Arg2 是否包含任何資訊 (請參閱表 1) 。

表 1. 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 無 無
xl無 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 支援與意見反應。