Baseline in Angular Gantt Chart Component
19 Jun 202619 minutes to read
The baseline feature in the Gantt Chart component enables comparison between original planned schedules and actual task execution timelines. This visualization provides clear insights into schedule deviations, helping assess project performance and identify areas requiring attention. Baseline functionality displays both the original planned timeline and current progress side-by-side for comprehensive project tracking.
Before implementing baseline functionality, ensure the data source includes baseline date fields and configure the taskFields object with appropriate field mappings. The baseline feature requires proper field mapping to display planned versus actual timelines effectively.
Baseline fields:
- baselineStartDate: Represents the originally planned start date of a task. This value is used to compare against the actual start date to identify schedule deviations.
- baselineEndDate: Represents the originally planned end date of a task. It is used to compare against the actual end date.
-
baselineDuration: Represents the total planned duration of the task. This value is critical for baseline visualization. To represent a baseline milestone, this property must be explicitly set to 0. Setting
baselineStartDateandbaselineEndDateto the same value without settingbaselineDurationto 0 will result in a one-day baseline task, not a milestone.
Implement baseline
To enable baseline, configure the Gantt Chart component by setting renderBaseline to true, mapping baselineStartDate, baselineEndDate, and optionally baselineDuration in taskFields. To customize appearance set the baselineColor property or the .e-baseline-bar CSS class for advanced styling.
export let projectData = [
{
TaskID: 1,
TaskName: 'Project Planning',
StartDate: new Date('02/04/2019'),
EndDate: new Date('02/08/2019'),
baselineStartDate: new Date('02/02/2019'),
baselineEndDate: new Date('02/06/2019'),
baselineDuration: '5' // Regular baseline.
},
{
TaskID: 2,
TaskName: 'Milestone Review',
StartDate: new Date('02/10/2019'),
EndDate: new Date('02/10/2019'),
baselineStartDate: new Date('02/09/2019'),
baselineEndDate: new Date('02/09/2019'),
baselineDuration: '0' // Milestone baseline.
}
];
public baselineColor: string = 'rgba(255, 107, 107, 0.8)'; // Semi-transparent red baseline..e-gantt .e-gantt-chart .e-baseline-bar {
height: 4px;
border-radius: 2px;
opacity: 0.9;
background-color: #4caf50;
}The following example demonstrates complete baseline configuration with proper field mapping:
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { GanttModule } from '@syncfusion/ej2-angular-gantt'
import { SelectionService } from '@syncfusion/ej2-angular-gantt'
import { Component, ViewEncapsulation, OnInit } from '@angular/core';
import { baselineData } from './data';
@Component({
imports: [ GanttModule ],
providers: [SelectionService],
standalone: true,
selector: 'app-root',
template:
`<ejs-gantt id="ganttDefault" height="430px" [dataSource]="data" [taskFields]="taskSettings" [renderBaseline]="true" baselineColor='red'></ejs-gantt>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
// Data for Gantt
public data?: Object[];
public taskSettings?: object;
public ngOnInit(): void {
this.data = baselineData;
this.taskSettings = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
baselineStartDate: "BaselineStartDate",
baselineEndDate: "BaselineEndDate",
baselineDuration: "BaselineDuration",
parentID: 'ParentID'
};
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));export let baselineData: Object[] = [
{ TaskID: 1, TaskName: 'Project Initiation', StartDate: new Date('04/02/2019'), EndDate: new Date('04/21/2019') },
{ TaskID: 2, TaskName: 'Identify Site location', BaselineStartDate: new Date('04/02/2019'), BaselineEndDate: new Date('04/06/2019'), StartDate: new Date('04/02/2019'), Duration: 0, Progress: 50, ParentID: 1 },
{ TaskID: 3, TaskName: 'Perform Soil test', BaselineStartDate: new Date('04/04/2019'), BaselineEndDate: new Date('04/09/2019'), StartDate: new Date('04/02/2019'), Duration: 4, Progress: 50, BaselineDuration: 5, ParentID: 1 },
{ TaskID: 4, TaskName: 'Soil test approval', BaselineStartDate: new Date('04/08/2019'), StartDate: new Date('04/02/2019'), Duration: 4, Progress: 50, BaselineDuration: 4, ParentID: 1 },
{ TaskID: 5, TaskName: 'Project Estimation', StartDate: new Date('04/02/2019'), EndDate: new Date('04/21/2019') },
{ TaskID: 6, TaskName: 'Develop floor plan for estimation', BaselineStartDate: new Date('04/04/2019'), BaselineEndDate: new Date('04/08/2019'), StartDate: new Date('04/04/2019'), Duration: 3, Progress: 50, ParentID: 5 },
{ TaskID: 7, TaskName: 'List materials', BaselineStartDate: new Date('04/02/2019'), BaselineEndDate: new Date('04/04/2019'), StartDate: new Date('04/04/2019'), Duration: 3, Progress: 50, BaselineDuration: 2, ParentID: 5 },
{ TaskID: 8, TaskName: 'Estimation approval', BaselineStartDate: new Date('04/02/2019'), StartDate: new Date('04/04/2019'), Duration: 0, Progress: 50, BaselineDuration: 0, ParentID: 5 }
];For a comprehensive demonstration of baseline functionality, explore the interactive sample.
Customize baseline using event
You can customize the baseline bar in the Gantt chart using the queryTaskbarInfo event.
import { IQueryTaskbarInfoEventArgs } from "@syncfusion/ej2-angular-gantt";
function queryTaskbarInfo(args: IQueryTaskbarInfoEventArgs) {
var element = args.rowElement.querySelector(".e-baseline-bar ");
if (element) {
element.style.background = "linear-gradient(red, yellow)";
}
}Customize baseline templates
The baselineTemplate property allows customization of baseline rendering by replacing the default baseline UI with a custom HTML structure. This enables advanced scenarios such as rendering additional baseline elements, visual indicators, or multiple baselines using task-specific data.
Set the baselineTemplate property with a template string or function. The template receives the task data object, which can be used to dynamically generate baseline elements.
Multiple baseline rendering using template
By default, the Gantt component supports a single baseline per task. However, using the baselineTemplate, you can extend this behavior to render multiple baselines by maintaining additional baseline data within a custom field in your data source.
This enables rich visualization scenarios such as:
- Comparing original vs revised schedules.
- Visualizing multiple planning phases.
- Highlighting deviations across timeline checkpoints.
The following example demonstrates how to render multiple baselines using baselineTemplate.
import { Component } from '@angular/core';
import { Gantt, Selection, DayMarkers, TaskFieldsModel, SplitterSettingsModel, SelectionService, GanttModule } from '@syncfusion/ej2-angular-gantt';
import { baselineData } from './data';
Gantt.Inject(Selection, DayMarkers);
@Component({
imports: [GanttModule],
providers: [SelectionService],
standalone: true,
selector: 'app-root',
template: `
<ejs-gantt
[dataSource]="data"
[taskFields]="taskSettings"
[splitterSettings]="splitterSettings"
[tooltipSettings]="tooltipSettings"
[allowSelection]="true"
[renderBaseline]="true"
[rowHeight]="60"
[taskbarHeight]="20"
gridLines="Both"
[highlightWeekends]="true"
[labelSettings]="labelSettings"
[baselineColor]="'red'"
height="450px"
[baselineTemplate]="baselineTemplate"
>
<e-columns>
<e-column field="TaskID" headerText="ID" textAlign="Left"></e-column>
<e-column field="TaskName" width="270" headerText="Name"></e-column>
<e-column field="BaselineStartDate" headerText="Baseline Start Date" width="180"></e-column>
<e-column field="BaselineDuration" headerText="Baseline Duration" width="180"></e-column>
<e-column field="BaselineStartDate1" type="date" format="yMd" headerText="Baseline1 Start Date" width="180"></e-column>
<e-column field="BaselineDuration1" headerText="Baseline1 Duration" width="180"></e-column>
<e-column field="BaselineStartDate2" type="date" format="yMd" headerText="Baseline2 Start Date" width="180"></e-column>
<e-column field="BaselineDuration2" headerText="Baseline2 Duration" width="180"></e-column>
</e-columns>
</ejs-gantt>
`
})
export class AppComponent {
public data: Object[] = baselineData;
public taskSettings: TaskFieldsModel = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
endDate: 'EndDate',
duration: 'Duration',
progress: 'Progress',
baselineStartDate: 'BaselineStartDate',
baselineEndDate: 'BaselineEndDate',
parentID: 'ParentID'
};
public splitterSettings: SplitterSettingsModel = {
columnIndex: 3
};
public tooltipSettings: Object = {
showTooltip: false
};
public labelSettings: Object = {
taskLabel: 'TaskName'
};
public baselineTemplate = (props: any): string => {
if (props.hasChildRecords || (props.data && props.data.hasChildRecords)) {
return '';
}
const gantt = (document.querySelector('ejs-gantt') as any).ej2_instances[0];
const taskRecord = props.taskData;
const ganttProperties = taskRecord.ganttProperties;
const chartRowsModule = gantt.chartRowsModule;
const baselineTop = chartRowsModule.baselineTop;
const baselineHeight = chartRowsModule.baselineHeight;
const taskBarHeight = chartRowsModule.taskBarHeight;
const milestoneHeight = chartRowsModule.milestoneHeight;
const milestoneMarginTop = chartRowsModule.milestoneMarginTop;
const rowHeight = gantt.rowHeight;
const renderBaseline = gantt.renderBaseline;
const enableRtl = gantt.enableRtl;
const taskSpacing = 9;
const baselineSpacing = 4;
function getLeft(date: any): number {
return gantt.dataOperation.getTaskLeft(new Date(date), false, ganttProperties.calendarContext);
}
function getWidth(start: any, duration: number): number {
if (!start || duration == null || duration === 0) return 0;
const end = new Date(start);
end.setDate(end.getDate() + duration);
const leftStart = getLeft(start);
const leftEnd = getLeft(end);
return leftEnd - leftStart;
}
function render(start: any, duration: number, index: number): string {
if (!start) return '';
const leftPosition = getLeft(start);
const width = getWidth(start, duration);
if (duration === 0) {
const milestoneSize = renderBaseline ? taskBarHeight : (taskBarHeight - 10);
const baselineMilestoneHeight = renderBaseline ? 5 : 2;
const leftPosition_ms = enableRtl
? (leftPosition - (milestoneHeight / 2) + 3)
: (leftPosition - (milestoneHeight / 2) + 1);
const marginTop =
(-Math.floor(rowHeight - milestoneMarginTop) + baselineMilestoneHeight) +
2 +
(index * baselineSpacing);
return '<div style="position:absolute;width:' + milestoneSize + 'px;height:' + milestoneSize + 'px;transform:rotate(45deg);' +
(enableRtl ? 'right:' : 'left:') + leftPosition_ms + 'px;margin-top:' + marginTop + 'px;"></div>';
}
return '<div style="position:absolute;' +
(enableRtl ? 'right:' : 'left:') + leftPosition + 'px;margin-top:' + (baselineTop + (index * taskSpacing)) +
'px;width:' + width + 'px;height:' + baselineHeight + 'px;"></div>';
}
return '<div>' +
render(taskRecord.taskData.BaselineStartDate, taskRecord.taskData.BaselineDuration, 0) +
render(taskRecord.taskData.BaselineStartDate1, taskRecord.taskData.BaselineDuration1, 1) +
render(taskRecord.taskData.BaselineStartDate2, taskRecord.taskData.BaselineDuration2, 2) +
'</div>';
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));export let baselineData: Object[] = [
{ TaskID: 1, TaskName: 'Consumer electronics launch', StartDate: new Date('2024-05-01'), EndDate: new Date('2024-05-14'), Progress: 58 },
{ TaskID: 2, TaskName: 'Design freeze', StartDate: new Date('2024-05-03'), Duration: 3, BaselineStartDate: new Date('2024-05-03'), BaselineDuration: 3, BaselineStartDate1: new Date('2024-05-03'), BaselineDuration1: 5, BaselineStartDate2: new Date('2024-05-03'), BaselineDuration2: 7, Progress: 100, ParentID: 1 },
{ TaskID: 3, TaskName: 'Prototype development', StartDate: new Date('2024-05-08'), Duration: 4, BaselineStartDate: new Date('2024-05-07'), BaselineDuration: 0, BaselineStartDate1: new Date('2024-05-08'), BaselineDuration1: 1, BaselineStartDate2: new Date('2024-05-09'), BaselineDuration2: 1, Progress: 90, ParentID: 1 },
{ TaskID: 4, TaskName: 'Tooling & mold setup', StartDate: new Date('2024-05-10'), Duration: 3, BaselineStartDate: new Date('2024-05-10'), BaselineDuration: 3, BaselineStartDate1: new Date('2024-05-10'), BaselineDuration1: 3, BaselineStartDate2: new Date('2024-05-10'), BaselineDuration2: 3, Progress: 70, ParentID: 1 },
{ TaskID: 5, TaskName: 'Quality certification', StartDate: new Date('2024-05-13'), Duration: 3, BaselineStartDate: new Date('2024-05-13'), BaselineDuration: 3, BaselineStartDate1: new Date('2024-05-14'), BaselineDuration1: 3, BaselineStartDate2: new Date('2024-05-15'), BaselineDuration2: 3, Progress: 60, ParentID: 1 },
{ TaskID: 6, TaskName: 'Pilot production run', StartDate: new Date('2024-05-10'), Duration: 4, BaselineStartDate: new Date('2024-05-10'), BaselineDuration: 3, BaselineStartDate1: new Date('2024-05-10'), BaselineDuration1: 2, BaselineStartDate2: new Date('2024-05-10'), BaselineDuration2: 1, Progress: 45, ParentID: 1 },
{ TaskID: 7, TaskName: 'Market launch', StartDate: new Date('2024-05-15'), Duration: 0, BaselineStartDate: new Date('2024-05-14'), BaselineDuration: 0, BaselineStartDate1: new Date('2024-05-15'), BaselineDuration1: 0, BaselineStartDate2: new Date('2024-05-16'), BaselineDuration2: 0, ParentID: 1 }
];