Hello,
I tried adding baselines under the tasks, but nothing appeared when saving the file as a PDF.
Project project = new Project { CalculationMode = CalculationMode.Manual };
Task parentTask =project.RootTask;
Task child1 = parentTask.Children.Add("Task 1");
Task child2 = parentTask.Children.Add("Task 2");
parentTask .Baselines.Add(new TaskBaseline(child1 )
{
BaselineNumber = BaselineType.Baseline,
Start = startDate,
Finish = endDate
});
parentTask .Baselines.Add(new TaskBaseline(child2)
{
BaselineNumber = BaselineType.Baseline,
Start = startDate,
Finish = endDate
});
project.SetBaseline(BaselineType.Baseline, new List<Task>(){child1, child2});
Version Aspose.Tasks 24.6.0
@michelhuang ,
Can you clarify the expected result?
Where should the baselines appear?
What presentation format (or View) do you specify when saving the project to PDF ?
also please note that you create a baseline for child1, but add it to Baselines collection of the parent task.
Baselines for child1 should be added to child1.Baselines collection.
Hello @vasiliy.sinitsyn ,
Thanks for the reply.
The development used the “GanttChart” presentation format.
I was expected that on the baseline is shown on the GanttChart for each task sets.
My bad, you’re right
Project project = new Project { CalculationMode = CalculationMode.Manual };
Task parentTask =project.RootTask;
Task child1 = parentTask.Children.Add("Task 1");
Task child2 = parentTask.Children.Add("Task 2");
child1.Baselines.Add(new TaskBaseline(child1 )
{
BaselineNumber = BaselineType.Baseline,
Start = startDate,
Finish = endDate
});
child2.Baselines.Add(new TaskBaseline(child2)
{
BaselineNumber = BaselineType.Baseline,
Start = startDate,
Finish = endDate
});
project.SetBaseline(BaselineType.Baseline, new List<Task>(){child1, child2});
PdfSaveOptions options = PdfSaveOptions() {PresentationFormat = PresentationFormat.GanttChart};
project.Save(outputPath, options);
@michelhuang ,
thank you for the details.
The rendering of bars for baselines in GanttChart is not supported at the moment.
We will add feature request to add the rendering of bars for baselines.
@michelhuang
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies .
Issue ID(s): TASKSNET-11245
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
michelhuang:
List<Task>
Hello @vasiliy.sinitsyn ,
I noticed that ticket TASKSNET-11245 has been resolved. Could you provide an example of how to render baseline bars?
Thanks,
@michelhuang ,
you can use the following ways:
Use MPP file where baseline bars are turned on as a template :
or
Add set up the corresponding (baseline) bar style, add it to the Gantt chart view and render it:
Project project = new Project();
project.StartDate = new DateTime(2024, 9, 14, 8, 0, 0);
var startDate = new DateTime(2024, 9, 16, 8, 0, 0);
var endDate = new DateTime(2024, 9, 24, 17, 0, 0);
Task parentTask = project.RootTask;
Task child1 = parentTask.Children.Add("Task 1");
child1.Duration = project.GetDuration(5, TimeUnitType.Day);
Task child2 = parentTask.Children.Add("Task 2");
child2.Duration = project.GetDuration(6, TimeUnitType.Day);
child1.Baselines.Add(new TaskBaseline(child1)
{
BaselineNumber = BaselineType.Baseline,
Start = startDate,
Finish = endDate
});
child2.Baselines.Add(new TaskBaseline(child2)
{
BaselineNumber = BaselineType.Baseline,
Start = startDate,
Finish = endDate
});
var ganttChartView = project.DefaultView as GanttChartView;
if (ganttChartView != null)
{
GanttBarStyle baselineStyle = new GanttBarStyle();
baselineStyle.ShowForCategories = new List<GanttBarShowFor>();
baselineStyle.ShowForCategories.Add(GanttBarShowFor.Active);
baselineStyle.ShowForCategories.Add(GanttBarShowFor.Normal);
baselineStyle.From = Field.TaskBaselineStart;
baselineStyle.To = Field.TaskBaselineFinish;
baselineStyle.MiddleShape = GanttBarMiddleShape.LineBottom;
baselineStyle.MiddleShapeColor = Color.Gray;
ganttChartView.BarStyles.Add(baselineStyle);
}
PdfSaveOptions options = new PdfSaveOptions()
{
ViewSettings = ganttChartView
};
project.Save("output.pdf", options);
Thank you, that was helpful!