Project) (圖表物件

Chart 物件代表 Project 中報表上的圖表。

註解

Project 中的 Chart 物件包含其他 Office 應用程式針對 Office Art 實作的標準成員。 例如,請參閱 Word、Excel 和 PowerPoint 的 VBA 物件模型中的 Chart 物件。

在 Project 中,圖表是由 Chart 物件所代表,而 Chart 物件則由 Shape 物件或 Report 物件中的 ShapeRange 集合所包含。 如需顯示專案物件模型階層中 Chart 物件的圖表,請參閱應用程式 和專案物件對應。

注意事項

未執行 Chart 物件的巨集錄製。 也就是說,當您在 Project 中錄製巨集,並在報表中手動新增圖表、新增圖表項目或手動格式化圖表時,系統不會記錄新增和操作圖表的步驟。

使用 Shapes.AddChart 方法將圖表新增到報表。 若要判斷 Shape 或 ShapeRange 是否包含圖表,請使用 HasChart 方法。

Project 中的 Chart 物件不會實作事件。 因此,Project 中的圖表無法如 Excel 一般,動畫處理成與滑鼠事件互動,或回應 [選取] 或 [計算] 等事件。

範例

下列範例會為使用中專案中的任務建立簡單的純量圖。 圖表會顯示 [實際工時]、[ 剩餘工時] 和 [工時 ] 預設欄位。

若要建立一些範例資料,請將四個工作新增到新專案、為這些工作指派本機資源,並設定工期和實際工時的各種值。 例如,試試看表 1 中的值。

表 1. 簡單圖表的範例資料

任務名稱 Duration 實際工時
T1 2D 16
T2 5D 19
T3 4D 7
T4 2D 0
Sub AddSimpleScalarChart()
    Dim chartReport As Report
    Dim reportName As String
    
    ' Add a report.
    reportName = "Simple scalar chart"
    Set chartReport = ActiveProject.Reports.Add(reportName)

    ' Add a chart.
    Dim chartShape As Shape
    Set chartShape = ActiveProject.Reports(reportName).Shapes.AddChart()
    
    chartShape.Chart.SetElement (msoElementChartTitleCenteredOverlay)
    chartShape.Chart.ChartTitle.Text = "Sample Chart for the Test1 project"
End Sub

當您執行 AddSimpleScalarChart 巨集時,Project 會建立報表並新增圖表。 圖表具有預設功能,除了標題是由要覆蓋在圖表上的 SetElement 屬性所指定,而不是在圖表上方的預設位置。

圖 1: 圖表會顯示表 1 中的資料

報表中的簡單純量圖 若要刪除圖表,您可以刪除包含圖表的圖形。 下列巨集會刪除由 AddSimpleScalarChart 巨集所建立之報表上的圖表,並將空白報表保留為使用中的檢視。

Sub DeleteTheShape()
    Dim i As Integer
    Dim reportName As String
    Dim theShape As MSProject.Shape
    
    reportName = "Simple scalar chart"
        
    For i = 1 To ActiveProject.Reports.Count
        If ActiveProject.Reports(i).Name = reportName Then
            Set theShape = ActiveProject.Reports(i).Shapes(1)
            theShape.Delete
        End If
    Next i
End Sub

若要刪除報表,請移至不同的檢視,然後開啟 [組合管理 ] 對話方塊。 報表作用中時,您無法刪除報表。 [召集人] 位於功能區的 [開發人員] 索引標籤上,也可以在 [管理] 功能表的 [報表群組] 的 [設計] 索引標籤上使用。 在 [組合管理] 對話方塊的 [報告] 索引標籤上,選取專案窗格中的 [簡單純量圖],然後選擇 [刪除]。 或者,執行下列巨集以刪除報表。

Sub DeleteTheReport()
    Dim i As Integer
    Dim reportName As String
    
    reportName = "Simple scalar chart"

    ' To delete the active report, change to another view.
    ViewApplyEx Name:="&Gantt Chart"
    
    ActiveProject.Reports(reportName).Delete
End Sub

方法

名稱
ApplyChartTemplate
ApplyCustomType
ApplyDataLabels
ApplyLayout
AutoFormat
Axes
ChartWizard
ClearToMatchColorStyle
ClearToMatchStyle
Copy
CopyPicture
Delete
Export
GetChartElement
Refresh
RefreshPivotTable
SaveChartTemplate
Select
SeriesCollection
SetDefaultChart
SetElement
SetSourceData
UpdateChartData

屬性

名稱
Application
AutoScaling
BackWall
BarShape
ChartArea
ChartColor
ChartData
ChartGroups
ChartStyle
ChartTitle
ChartType
Creator
DataTable
DepthPercent
DisplayBlanksAs
Elevation
Floor
Format
GapDepth
HasAxis
HasDataTable
HasLegend
HasTitle
HeightPercent
Legend
Parent
Perspective
PivotLayout
PlotArea
PlotBy
PlotVisibleOnly
RightAngleAxes
Rotation
Shapes
ShowAllFieldButtons
ShowAxisFieldButtons
ShowDataLabelsOverMaximum
ShowLegendFieldButtons
ShowReportFilterFieldButtons
ShowValueFieldButtons
SideWall
Walls

另請參閱

Shape 物件

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。