Text field rendering of the gantt view

Hello,

I have searched for information regarding modifying the font properties of the text fields in the Gantt view, but I haven’t been able to find any relevant details. Is it possible to change the font settings?

Version Aspose.Tasks 24.9.0

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);

   //Set the right field for displaying task notes
    gantt.BarStyles.ForEach(barstyle => taskStyle.RightField = Field.TaskSheetNotes);
}

PdfSaveOptions options = new PdfSaveOptions()
{
    ViewSettings = ganttChartView
};

project.Save("output.pdf", options);

@michelhuang

Yes, it is possible to change the font properties of the text fields in the Gantt view using Aspose.Tasks. You can customize the appearance of the Gantt chart by modifying the properties of the GanttBarStyle class, which allows you to set various fields for displaying task information.

Here’s an example of how you can customize the text fields in the Gantt view:

using Aspose.Tasks;
using Aspose.Tasks.Saving;
using Aspose.Tasks.Visualization;
using System;
using System.Collections.Generic;
using System.Drawing;

class Program
{
    static void Main()
    {
        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
            {
                ShowForCategories = new List<GanttBarShowFor>
                {
                    GanttBarShowFor.Active,
                    GanttBarShowFor.Normal
                },
                From = Field.TaskBaselineStart,
                To = Field.TaskBaselineFinish,
                MiddleShape = GanttBarMiddleShape.LineBottom,
                MiddleShapeColor = Color.Gray,
                RightField = Field.TaskSheetNotes // Set the field for displaying task notes
            };

            ganttChartView.BarStyles.Add(baselineStyle);
        }

        PdfSaveOptions options = new PdfSaveOptions()
        {
            ViewSettings = ganttChartView
        };

        project.Save("output.pdf", options);
    }
}

In this example, the RightField property of the GanttBarStyle is set to display task notes. You can customize other fields such as LeftField, TopField, and BottomField to display different task attributes. Additionally, you can modify the MiddleShape and MiddleShapeColor to change the appearance of the Gantt bars.

For more detailed customization options, you can refer to the Aspose documentation on configuring Gantt chart views, which provides comprehensive guidance on how to manipulate various properties of the Gantt chart.

Sources:
[1]: Configure Gantt Chart View in Aspose.Tasks Projects
[2]: Working with Project Views - Aspose Documentation

@michelhuang
currently the font of LeftField, TopField, BottomField label cannot be customized - default font is used.

We have opened the following new ticket in our internal issue tracking system and will deliver the fix according to the terms mentioned in Free Support Policies.

Issue ID(s): TASKSNET-11302

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.

The issues you have found earlier (filed as TASKSNET-11302) have been fixed in this update.

Download