Project Views

Reading Specific Gantt Chart View Data

Gantt charts provide a graphical representation of a project plan. Sometimes it is necessary to read particular data associated with a Gantt chart view, such as the bar-style information, gridline properties, progress lines properties and time scale information. Aspose.Tasks for C++ API provides the capability to access all the properties individually with the GanttChartView class that inherits from View. This feature is supported for Microsoft Project 2003, 2007, 2010 and 2013 MPP file formats.

 1System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"ReadSpecificGantChartViewData.mpp");
 2    
 3System::SharedPtr<GanttChartView> view = System::DynamicCast_noexcept<Aspose::Tasks::GanttChartView>(project->get_Views()->ToList()->idx_get(0));
 4System::Console::WriteLine(System::String(u"Is Bar Rounding: ") + view->get_BarRounding());
 5System::Console::WriteLine(System::String(u"Show Bar Splits? : ") + view->get_ShowBarSplits());
 6System::Console::WriteLine(System::String(u"Show Drawings? : ") + view->get_ShowDrawings());
 7System::Console::WriteLine(System::String(u"Roll Up Gantt Bars? ") + view->get_RollUpGanttBars());
 8System::Console::WriteLine(System::String(u"Hide Rollup Bars When Summary Expa0nded: ") + view->get_HideRollupBarsWhenSummaryExpanded());
 9System::Console::WriteLine(System::String(u"Bar Size: ") + System::ObjectExt::ToString(view->get_BarSize()));
10System::Console::WriteLine(System::String(u"Bar Style: ") + view->get_BarStyles()->get_Count());
11System::Console::WriteLine(u"\n************************ RETREIVING BAR STYLES INFORMATION FROM THE VIEW *********************");
12int32_t i = 0;
13    
14{
15    auto barStyle_enumerator = (view->get_BarStyles())->GetEnumerator();
16    decltype(barStyle_enumerator->get_Current()) barStyle;
17    while (barStyle_enumerator->MoveNext() && (barStyle = barStyle_enumerator->get_Current(), true))
18    {
19        System::Console::WriteLine(System::String(u"Name: ") + barStyle->get_Name());
20        System::Console::WriteLine(System::String(u"ShowForCategories: ") + System::ObjectExt::ToString(barStyle->get_ShowForCategories()));
21        System::Console::WriteLine(System::String(u"ShowForTaskUid: ") + System::ObjectExt::ToString(barStyle->get_ShowForTaskUid()));
22        System::Console::WriteLine(System::String(u"Row: ") + barStyle->get_Row());
23        System::Console::WriteLine(System::String(u"From: ") + System::ObjectExt::ToString(barStyle->get_From()));
24        System::Console::WriteLine(System::String(u"To: ") + System::ObjectExt::ToString(barStyle->get_To()));
25        System::Console::WriteLine(System::String(u"MiddleShape: ") + System::ObjectExt::ToString(barStyle->get_MiddleShape()));
26        System::Console::WriteLine(System::String(u"MiddleShapeColor: ") + barStyle->get_MiddleShapeColor());
27        System::Console::WriteLine(System::String(u"StartShape: ") + System::ObjectExt::ToString(barStyle->get_StartShape()));
28        System::Console::WriteLine(System::String(u"EndShape: ") + System::ObjectExt::ToString(barStyle->get_EndShape()));
29        System::Console::WriteLine(System::String(u"EndShapeColor: ") + barStyle->get_EndShapeColor());
30        i++;
31    }
32}
33    
34System::Console::WriteLine(System::String(u"Grid Lines Count: ") + view->get_Gridlines()->get_Count());
35System::SharedPtr<Gridlines> gridlines = view->get_Gridlines()->idx_get(0);
36System::Console::WriteLine(u"\n************************ RETREIVING GRID LINES PROPERTIES *********************");
37System::Console::WriteLine(System::String(u"GridLine Type: ") + System::ObjectExt::ToString(gridlines->get_Type()));
38System::Console::WriteLine(System::String(u"Gridlines Internval: ") + gridlines->get_Interval());
39System::Console::WriteLine(System::String(u"Gridlines Color: ") + gridlines->get_NormalColor());
40System::Console::WriteLine(System::String(u"Gridlines NormalPattern: ") + System::ObjectExt::ToString(gridlines->get_NormalPattern()));
41System::Console::WriteLine(System::String(u"Gridlines IntervalPattern: ") + System::ObjectExt::ToString(gridlines->get_IntervalPattern()));
42System::Console::WriteLine(System::String(u"Gridlines IntervalColor: ") + gridlines->get_IntervalColor());
43System::Console::WriteLine(u"\n************************ RETREIVING PROGRESS LINES PROPERTIES *********************");
44System::Console::WriteLine(u"ProgressLInes.BeginAtDate: ", System::ObjectExt::Box<System::DateTime>(view->get_ProgressLines()->get_BeginAtDate()));
45System::Console::WriteLine(System::String(u"ProgressLines.isBaselinePlan: ") + view->get_ProgressLines()->get_IsBaselinePlan());
46System::Console::WriteLine(System::String(u"ProgressLines.DisplaySelected: ") + view->get_ProgressLines()->get_DisplaySelected());
47System::Console::WriteLine(System::String(u"ProgressLines.SelectedDates.Count: ") + view->get_ProgressLines()->get_SelectedDates()->get_Count());
48System::Console::WriteLine(System::String(u"ProgressLines.SelectedDates[0]: ") + view->get_ProgressLines()->get_SelectedDates()->idx_get(0));
49System::Console::WriteLine(System::String(u"ProgressLines.SelectedDates[1]: ") + view->get_ProgressLines()->get_SelectedDates()->idx_get(1));
50System::Console::WriteLine(System::String(u"ProgressLines.SelectedDates[2]: ") + view->get_ProgressLines()->get_SelectedDates()->idx_get(2));
51System::Console::WriteLine(System::String(u"ProgressLines.DisplayAtRecurringIntervals: ") + view->get_ProgressLines()->get_DisplayAtRecurringIntervals());
52System::Console::WriteLine(System::String(u"ProgressLines.RecurringInterval.Interval: ") + System::ObjectExt::ToString(Aspose::Tasks::Visualization::Interval::Weekly), System::ObjectExt::Box<Interval>(view->get_ProgressLines()->get_RecurringInterval()->get_Interval()));
53System::Console::WriteLine(System::String(u"ProgressLines.RecurringInterval.WeeklyDays.Count") + view->get_ProgressLines()->get_RecurringInterval()->get_WeeklyDays()->get_Count());
54System::Console::WriteLine(System::String(u"Recurring Interval.WeeklyDays: ") + view->get_ProgressLines()->get_RecurringInterval()->get_WeeklyDays());
55System::Console::WriteLine(System::String(u"Recurring Interval.DayType.Saturday: ") + view->get_ProgressLines()->get_RecurringInterval()->get_WeeklyDays());
56System::Console::WriteLine(System::String(u"Recurring Interval.DayType.Sunday: ") + view->get_ProgressLines()->get_RecurringInterval()->get_WeeklyDays());
57System::Console::WriteLine(System::String(u"ProgressLines.ShowDate: ") + view->get_ProgressLines()->get_ShowDate());
58System::Console::WriteLine(System::String(u"ProgressLines.ProgressPointShape: ") + System::ObjectExt::ToString(view->get_ProgressLines()->get_ProgressPointShape()));
59System::Console::WriteLine(System::String(u"ProgressLines.ProgressPointColor: ") + view->get_ProgressLines()->get_ProgressPointColor());
60System::Console::WriteLine(System::String(u"ProgressLines.LineColor: ") + System::Drawing::Color::get_Red(), System::ObjectExt::Box<System::Drawing::Color>(view->get_ProgressLines()->get_LineColor()));
61System::Console::WriteLine(System::String(u"ProgressLines.LinePattern: ") + System::ObjectExt::ToString(Aspose::Tasks::Visualization::LinePattern::Solid), System::ObjectExt::Box<LinePattern>(view->get_ProgressLines()->get_LinePattern()));
62System::Console::WriteLine(System::String(u"ProgressLines.OtherProgressPointShape: ") + System::ObjectExt::ToString(view->get_ProgressLines()->get_OtherProgressPointShape()));
63System::Console::WriteLine(System::String(u"ProgressLines.OtherProgressPointColor: ") + System::ObjectExt::ToString(view->get_ProgressLines()->get_OtherProgressPointColor()));
64System::Console::WriteLine(System::String(u"ProgressLines.OtherLineColor: ") + view->get_ProgressLines()->get_OtherLineColor());
65System::Console::WriteLine(u"\n************************ BOTTOM TIMESCALE IFORMATION ******************");
66System::Console::WriteLine(System::String(u"BottomTimescaleTier.Count:") + view->get_BottomTimescaleTier()->get_Count());
67System::Console::WriteLine(System::String(u"BottomTimescaleTier.Unit:") + System::ObjectExt::ToString(Aspose::Tasks::Visualization::TimescaleUnit::Days), System::ObjectExt::Box<System::String>(System::ObjectExt::ToString(view->get_BottomTimescaleTier()->get_Unit())));
68System::Console::WriteLine(System::String(u"BottomTimescaleTier.UsesFiscalYear: ") + view->get_BottomTimescaleTier()->get_UsesFiscalYear());
69System::Console::WriteLine(System::String(u"BottomTimescaleTier.Alignment: ") + System::ObjectExt::ToString(System::Drawing::StringAlignment::Center), System::ObjectExt::Box<System::String>(System::ObjectExt::ToString(view->get_BottomTimescaleTier()->get_Alignment())));
70System::Console::WriteLine(System::String(u"BottomTimescaleTier.ShowTicks: ") + System::Convert::ToString(view->get_BottomTimescaleTier()->get_ShowTicks()));
71System::Console::WriteLine(System::String(u"BottomTimescaleTier.Label:") + System::ObjectExt::ToString(Aspose::Tasks::Visualization::DateLabel::DayDi), System::ObjectExt::Box<DateLabel>(view->get_BottomTimescaleTier()->get_Label()));
72System::Console::WriteLine(u"\n************************ MIDDLE TIMESCALE IFORMATION ******************");
73System::Console::WriteLine(System::String(u"MiddleTimescaleTier.Count:") + view->get_MiddleTimescaleTier()->get_Count());
74System::Console::WriteLine(System::String(u"MiddleTimescaleTier.Unit:") + System::ObjectExt::ToString(Aspose::Tasks::Visualization::TimescaleUnit::Days), System::ObjectExt::Box<System::String>(System::ObjectExt::ToString(view->get_MiddleTimescaleTier()->get_Unit())));
75System::Console::WriteLine(System::String(u"MiddleTimescaleTier.UsesFiscalYear: ") + view->get_MiddleTimescaleTier()->get_UsesFiscalYear());
76System::Console::WriteLine(System::String(u"MiddleTimescaleTier.Alignment: ") + System::ObjectExt::ToString(System::Drawing::StringAlignment::Center), System::ObjectExt::Box<System::String>(System::ObjectExt::ToString(view->get_MiddleTimescaleTier()->get_Alignment())));
77System::Console::WriteLine(System::String(u"MiddleTimescaleTier.ShowTicks: ") + System::Convert::ToString(view->get_MiddleTimescaleTier()->get_ShowTicks()));
78System::Console::WriteLine(System::String(u"MiddleTimescaleTier.Label:") + System::ObjectExt::ToString(Aspose::Tasks::Visualization::DateLabel::DayDi), System::ObjectExt::Box<DateLabel>(view->get_MiddleTimescaleTier()->get_Label()));
79System::Console::WriteLine(u"\n************************ TOP TIMESCALE IFORMATION ******************");
80System::Console::WriteLine(System::String(u"TopTimescaleTier.Unit:") + System::ObjectExt::ToString(Aspose::Tasks::Visualization::TimescaleUnit::Days), System::ObjectExt::Box<System::String>(System::ObjectExt::ToString(view->get_TopTimescaleTier()->get_Unit())));
81System::Console::WriteLine(System::String(u"TopTimescaleTier.UsesFiscalYear: ") + view->get_TopTimescaleTier()->get_UsesFiscalYear());
82System::Console::WriteLine(System::String(u"TopTimescaleTier.Alignment: ") + System::ObjectExt::ToString(System::Drawing::StringAlignment::Center), System::ObjectExt::Box<System::String>(System::ObjectExt::ToString(view->get_TopTimescaleTier()->get_Alignment())));
83System::Console::WriteLine(System::String(u"TopTimescaleTier.ShowTicks: ") + System::Convert::ToString(view->get_TopTimescaleTier()->get_ShowTicks()));
84System::Console::WriteLine(u"TopTimescaleTier.Label: ", System::ObjectExt::Box<System::String>(System::ObjectExt::ToString(view->get_TopTimescaleTier()->get_Label())));

Configure Gantt Chart View by Showing Selected Custom Fields

Extended attributes added to a project may be assigned to a task. It may be desirable to add this custom field to a saved MPP file’s default view, or you might want selected custom fields to be shown automatically rather than selecting them manually. This article describes how to achieve this by customizing the Table of a Project.

 1System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"Project5.mpp");
 2        
 3// Create a new project task
 4System::SharedPtr<Task> task = project->get_RootTask()->get_Children()->Add(u"New Activity");
 5        
 6// Define new custom attribute
 7System::SharedPtr<ExtendedAttributeDefinition> text1Definition = ExtendedAttributeDefinition::CreateTaskDefinition(Aspose::Tasks::ExtendedAttributeTask::Text1, nullptr);
 8project->get_ExtendedAttributes()->Add(text1Definition);
 9// Add custom text attribute to created task.
10task->get_ExtendedAttributes()->Add(text1Definition->CreateExtendedAttribute(System::String(u"Activity attribute")));
11        
12// Customize table by adding text attribute field
13System::SharedPtr<TableField> attrField = System::MakeObject<TableField>();
14attrField->set_Field(Aspose::Tasks::Field::TaskText1);
15attrField->set_Width(20);
16attrField->set_Title(u"Custom attribute");
17attrField->set_AlignTitle(System::Drawing::StringAlignment::Center);
18attrField->set_AlignData(System::Drawing::StringAlignment::Center);
19System::SharedPtr<Table> table = project->get_Tables()->ToList()->idx_get(0);
20table->get_TableFields()->Insert(3, attrField);
21        
22// Save project as MPP
23project->Save(dataDir + u"ConfigureTheGantChartViewShowSelectedColumnFields_out.mpp", [&]{ auto tmp_0 = System::MakeObject<MPPSaveOptions>(); tmp_0->set_WriteViewData(true); return tmp_0; }());

Customizing Timescale Tier Labels according to Current Culture Information

Aspose.Tasks for C++ API provides the capability to customize Timescale tier labels according to the current CultureInfo of the machine. The DateTimeConverter(DateTime date) delegate provides a converter method to convert date to a string in view timescale tiers. In addition, TimescaleTier.DateTimeConverter enables rendering of date in the desired format.

 1System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"Project5.mpp");
 2    
 3// Add task links
 4project->get_TaskLinks()->Add(project->get_RootTask()->get_Children()->Add(u"Task 1"), project->get_RootTask()->get_Children()->Add(u"Task 2"));
 5    
 6System::SharedPtr<GanttChartView> view = System::DynamicCast<Aspose::Tasks::GanttChartView>(project->get_DefaultView());
 7    
 8// This code is added for better visualization
 9view->get_MiddleTimescaleTier()->set_Unit(Aspose::Tasks::Visualization::TimescaleUnit::Months);
10project->Set(Prj::TimescaleStart(), System::DateTime(2012, 8, 6));
11    
12// Customize middle tier dates
13    
14// CSPORTCPP: [WARNING] Using local variables. Make sure that local function ptr does not leave the current scope.
15std::function<System::String(System::DateTime date)> _local_func_0 = [](System::DateTime date)
16{
17    return System::MakeArray<System::String>({u"Янв.", u"Фев.", u"Мар.", u"Апр.", u"Май", u"Июнь", u"Июль", u"Авг.", u"Сен.", u"Окт.", u"Ноя.", u"Дек."})->idx_get(date.get_Month() - 1);
18};
19    
20view->get_MiddleTimescaleTier()->set_DateTimeConverter(_local_func_0);
21project->Save(dataDir + u"CustomizeTimescaleTierLabels_out.pdf", Aspose::Tasks::Saving::SaveFileFormat::PDF);

Setting Timescale Count for Project

The TimeScaleTier class makes it possible to set the TimeScale count information for a project. The below example shows how to achieve this objective using the Aspose.Tasks API

 1System::SharedPtr<Project> project = System::MakeObject<Project>();
 2    
 3// Init Gantt Chart View
 4System::SharedPtr<GanttChartView> view = System::MakeObject<GanttChartView>();
 5    
 6// Set Time Scale count
 7view->get_BottomTimescaleTier()->set_Count(2);
 8view->get_BottomTimescaleTier()->set_ShowTicks(false);
 9view->get_MiddleTimescaleTier()->set_Count(2);
10view->get_MiddleTimescaleTier()->set_ShowTicks(false);
11    
12// Add Gantt Chart View to project
13project->get_Views()->Add(view);
14    
15// Add some test data to project
16System::SharedPtr<Task> task1 = project->get_RootTask()->get_Children()->Add(u"Task 1");
17System::SharedPtr<Task> task2 = project->get_RootTask()->get_Children()->Add(u"Task 2");
18task1->Set<Duration>(Tsk::Duration(), task1->get_ParentProject()->GetDuration(24, Aspose::Tasks::TimeUnitType::Hour));
19task2->Set<Duration>(Tsk::Duration(), task1->get_ParentProject()->GetDuration(40, Aspose::Tasks::TimeUnitType::Hour));
20project->Save(dataDir + u"SetTimeScaleCount_out.pdf", Aspose::Tasks::Saving::SaveFileFormat::PDF);

Support for Text Styling

Text styling can be applied to a Gantt Chart View using TableTextStyle as shown in the following code sample.

 1// The path to the documents directory.
 2System::String dataDir = RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
 3System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"Project5.mpp");
 4// Create a new project task
 5auto ganttChartView = System::DynamicCast_noexcept<Aspose::Tasks::GanttChartView>(project->get_Views()->ToList()->idx_get(0));
 6if (ganttChartView != nullptr)
 7{
 8    ganttChartView->get_TableTextStyles()->Clear();
 9    ganttChartView->get_TableTextStyles()->Add([&]{ auto tmp_0 = System::MakeObject<TableTextStyle>(1); tmp_0->set_Color(System::Drawing::Color::get_Red()); tmp_0->set_Field(Aspose::Tasks::Field::TaskName); return tmp_0; }());
10    ganttChartView->get_TableTextStyles()->Add([&]{ auto tmp_1 = System::MakeObject<TableTextStyle>(1); tmp_1->set_Color(System::Drawing::Color::get_Gray()); tmp_1->set_Field(Aspose::Tasks::Field::TaskDurationText); return tmp_1; }());
11    ganttChartView->get_TableTextStyles()->Add([&]{ auto tmp_2 = System::MakeObject<TableTextStyle>(2); tmp_2->set_Color(System::Drawing::Color::get_Blue()); tmp_2->set_FontStyle(System::Drawing::FontStyle::Bold | System::Drawing::FontStyle::Italic | System::Drawing::FontStyle::Underline); return tmp_2; }());
12}

Saving MPP with Default GanttChartView

The following code example demonstrates the ability to save the MPP by setting the default view as a Gantt Chart.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.