How can I help you?
Timeline in ASP.NET CORE Gantt Component
24 Mar 202624 minutes to read
In the Gantt control, timeline is used to represent the project duration as individual cells with defined unit and formats.
Timeline view modes
Gantt contains the following in-built timeline view modes:
- Hour
- Week
- Month
- Year
Timescale mode in Gantt can be defined by using TimelineViewMode property and also we can define timescale mode of top tier and bottom tier by using TopTier.Unit and BottomTier.Unit properties.
Week timeline mode
In the Week timeline mode, the upper part of the schedule header displays the weeks, whereas the bottom half of the header displays the days. Refer to the following code example.
<ejs-gantt id='Gantt' dataSource="ViewBag.dataSource" height="450px">
<e-gantt-taskfields id="TaskId" name="TaskName" startDate="StartDate"
endDate="EndDate" duration="Duration" progress="Progress" child="SubTasks">
</e-gantt-taskfields>
<e-gantt-timelinesettings timelineViewMode="Week"></e-gantt-timelinesettings>
</ejs-gantt>public IActionResult Index()
{
ViewBag.DataSource = GanttData.ProjectNewData();
return View();
}
Month timeline mode
In the Month timeline mode, the upper part of the schedule header displays the months, whereas the bottom header of the schedule displays its corresponding weeks. Refer to the following code example.
<ejs-gantt id='Gantt' dataSource="ViewBag.dataSource" height="450px">
<e-gantt-taskfields id="TaskId" name="TaskName" startDate="StartDate"
endDate="EndDate" duration="Duration" progress="Progress" child="SubTasks">
</e-gantt-taskfields>
<e-gantt-timelinesettings timelineUnitSize="80" timelineViewMode="Month"></e-gantt-timelinesettings>
</ejs-gantt>public IActionResult Index()
{
ViewBag.DataSource = GanttData.ProjectNewData();
return View();
}
Year timeline mode
In the Year timeline mode, the upper schedule header displays the years whereas, the bottom header displays its corresponding months. Refer to the following code example.
<ejs-gantt id='Gantt' dataSource="ViewBag.dataSource" height="450px">
<e-gantt-taskfields id="TaskId" name="TaskName" startDate="StartDate"
endDate="EndDate" duration="Duration" progress="Progress" child="SubTasks">
</e-gantt-taskfields>
<e-gantt-timelinesettings timelineUnitSize="80" timelineViewMode="Year"></e-gantt-timelinesettings>
</ejs-gantt>public IActionResult Index()
{
ViewBag.DataSource = GanttData.ProjectNewData();
return View();
}
Day timeline mode
In the Day timeline mode, the upper part of the header displays the days whereas, the bottom schedule header displays its corresponding hours. Refer to the following code example.
<ejs-gantt id='Gantt' dataSource="ViewBag.dataSource" height="450px" durationUnit="Hour" dateFormat="M/d/yyyy hh:mm:ss tt">
<e-gantt-taskfields id="TaskId" name="TaskName" startDate="StartDate"
endDate="EndDate" duration="Duration" progress="Progress" child="SubTasks">
</e-gantt-taskfields>
<e-gantt-timelinesettings timelineViewMode="Day"></e-gantt-timelinesettings>
</ejs-gantt>public IActionResult Index()
{
ViewBag.DataSource = ganttData();
return View();
}
public static List<GanttDataSource> ganttData()
{
List<GanttDataSource> GanttDataSourceCollection = new List<GanttDataSource>();
GanttDataSource Record1 = new GanttDataSource()
{
TaskId = 1,
TaskName = "Project initiation",
StartDate = new DateTime(2019, 04, 02),
EndDate = new DateTime(2019, 04, 21),
SubTasks = new List<GanttDataSource>(),
};
GanttDataSource Child1 = new GanttDataSource()
{
TaskId = 2,
TaskName = "Identify site location",
StartDate = new DateTime(2019, 04, 02),
Duration = 5,
Progress = 70,
};
GanttDataSource Child2 = new GanttDataSource()
{
TaskId = 3,
TaskName = "Perform soil test",
StartDate = new DateTime(2019, 04, 02),
Duration = 5,
Progress = 50,
};
GanttDataSource Child3 = new GanttDataSource()
{
TaskId = 4,
TaskName = "Soil test approval",
StartDate = new DateTime(2019, 04, 02),
Duration = 5,
Progress = 50
};
Record1.SubTasks.Add(Child1);
Record1.SubTasks.Add(Child2);
Record1.SubTasks.Add(Child3);
GanttDataSource Record2 = new GanttDataSource()
{
TaskId = 5,
TaskName = "Project estimation",
StartDate = new DateTime(2019, 04, 02),
EndDate = new DateTime(2019, 04, 21),
SubTasks = new List<GanttDataSource>(),
};
GanttDataSource Child4 = new GanttDataSource()
{
TaskId = 6,
TaskName = "Develop floor plan for estimation",
StartDate = new DateTime(2019, 04, 02, 10, 10, 0),
Duration = 5,
Progress = 70,
};
GanttDataSource Child5 = new GanttDataSource()
{
TaskId = 7,
TaskName = "List materials",
StartDate = new DateTime(2019, 04, 02, 10, 10, 0),
Duration = 5,
Progress = 50,
};
Record2.SubTasks.Add(Child4);
Record2.SubTasks.Add(Child5);
GanttDataSourceCollection.Add(Record1);
GanttDataSourceCollection.Add(Record2);
return GanttDataSourceCollection;
}
public class GanttDataSource
{
public int TaskId { get; set; }
public string TaskName { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public int? Duration { get; set; }
public int Progress { get; set; }
public List<GanttDataSource> SubTasks { get; set; }
}
Hour timeline mode
An Hour timeline mode tracks the tasks in minutes scale. In this mode, the upper schedule header displays hour scale and the lower schedule header displays its corresponding minutes.
<ejs-gantt id='Gantt' dataSource="ViewBag.dataSource" height="450px" durationUnit="Minute" dateFormat="M/d/yyyy hh:mm:ss tt">
<e-gantt-taskfields id="TaskId" name="TaskName" startDate="StartDate"
endDate="EndDate" duration="Duration" progress="Progress" child="SubTasks">
</e-gantt-taskfields>
<e-gantt-timelinesettings timelineViewMode="Hour"></e-gantt-timelinesettings>
</ejs-gantt>public IActionResult Index()
{
ViewBag.DataSource = ganttData();
return View();
}
public static List<GanttDataSource> ganttData()
{
List<GanttDataSource> GanttDataSourceCollection = new List<GanttDataSource>();
GanttDataSource Record1 = new GanttDataSource()
{
TaskId = 1,
TaskName = "Project initiation",
StartDate = new DateTime(2019, 04, 02),
EndDate = new DateTime(2019, 04, 21),
SubTasks = new List<GanttDataSource>(),
};
GanttDataSource Child1 = new GanttDataSource()
{
TaskId = 2,
TaskName = "Identify site location",
StartDate = new DateTime(2019, 04, 02),
Duration = 5,
Progress = 70,
};
GanttDataSource Child2 = new GanttDataSource()
{
TaskId = 3,
TaskName = "Perform soil test",
StartDate = new DateTime(2019, 04, 02),
Duration = 5,
Progress = 50,
};
GanttDataSource Child3 = new GanttDataSource()
{
TaskId = 4,
TaskName = "Soil test approval",
StartDate = new DateTime(2019, 04, 02),
Duration = 5,
Progress = 50,
};
Record1.SubTasks.Add(Child1);
Record1.SubTasks.Add(Child2);
Record1.SubTasks.Add(Child3);
GanttDataSource Record2 = new GanttDataSource()
{
TaskId = 5,
TaskName = "Project estimation",
StartDate = new DateTime(2019, 04, 02),
EndDate = new DateTime(2019, 04, 21),
SubTasks = new List<GanttDataSource>(),
};
GanttDataSource Child4 = new GanttDataSource()
{
TaskId = 6,
TaskName = "Develop floor plan for estimation",
StartDate = new DateTime(2019, 04, 02, 8, 10, 0),
Duration = 5,
Progress = 70,
};
GanttDataSource Child5 = new GanttDataSource()
{
TaskId = 7,
TaskName = "List materials",
StartDate = new DateTime(2019, 04, 02, 8, 10, 0),
Duration = 5,
Progress = 50,
};
Record2.SubTasks.Add(Child4);
Record2.SubTasks.Add(Child5);
GanttDataSourceCollection.Add(Record1);
GanttDataSourceCollection.Add(Record2);
return GanttDataSourceCollection;
}
public class GanttDataSource
{
public int TaskId { get; set; }
public string TaskName { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public int? Duration { get; set; }
public int Progress { get; set; }
public List<GanttDataSource> SubTasks { get; set; }
}
Timeline view dates
The Gantt Chart control supports rendering a fixed timeline range using the viewStartDate and viewEndDate properties. These properties allow the visible portion of the timeline to be explicitly defined and locked within the Gantt chart UI, independent of the project’s overall scheduling boundaries defined by projectStartDate and projectEndDate. The projectStartDate and projectEndDate values represent the full scheduling window for the project and are used for baseline processing, critical-path calculations, and project-level reporting. By default, both viewStartDate and viewEndDate are set to auto. The following example demonstrates how to configure a custom timeline view range.
@{
ViewData["Title"] = "Home Page";
var dataSource = ViewBag.DataSource;
}
<ejs-gantt id="GanttDefault" height="430px" dataSource="ViewBag.DataSource" projectStartDate="03/31/2019" projectEndDate="04/31/2019">
<e-gantt-taskfields id="TaskID" name="TaskName" startDate="StartDate" duration="Duration" progress="Progress" parentID="ParentID">
</e-gantt-taskfields>
<e-gantt-timelinesettings viewStartDate="04/03/2019" viewEndDate="04/07/2019">
</e-gantt-timelinesettings>
<e-gantt-columns>
<e-gantt-column field="TaskID"></e-gantt-column>
<e-gantt-column field="TaskName"></e-gantt-column>
<e-gantt-column field="StartDate"></e-gantt-column>
<e-gantt-column field="Duration"></e-gantt-column>
<e-gantt-column field="Progress"></e-gantt-column>
</e-gantt-columns>
</ejs-gantt>
<script></script>namespace WebApplication1.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
ViewBag.DataSource = GanttData.GetData();
return View();
}
public class GanttData
{
public int TaskID { get; set; }
public string? TaskName { get; set; }
public DateTime StartDate { get; set; }
public int? Duration { get; set; }
public int? Progress { get; set; }
public int? ParentID { get; set; }
public static List<GanttData> GetData()
{
return new List<GanttData>
{
new GanttData { TaskID = 1, TaskName = "Project Initiation", StartDate = DateTime.Parse("02/04/2019") },
new GanttData { TaskID = 2, TaskName = "Identify Site location", StartDate = DateTime.Parse("02/04/2019"), Duration = 4, Progress = 50, ParentID = 1 },
new GanttData { TaskID = 3, TaskName = "Perform Soil test", StartDate = DateTime.Parse("02/04/2019"), Duration = 4, Progress = 50, ParentID = 1 },
new GanttData { TaskID = 4, TaskName = "Soil test approval", StartDate = DateTime.Parse("02/04/2019"), Duration = 4, Progress = 50, ParentID = 1 },
new GanttData { TaskID = 5, TaskName = "Project Estimation", StartDate = DateTime.Parse("02/04/2019") },
new GanttData { TaskID = 6, TaskName = "Develop floor plan for estimation", StartDate = DateTime.Parse("04/04/2019"), Duration = 3, Progress = 50, ParentID = 5 },
new GanttData { TaskID = 7, TaskName = "List materials", StartDate = DateTime.Parse("04/04/2019"), Duration = 3, Progress = 50, ParentID = 5 },
new GanttData { TaskID = 8, TaskName = "Estimation approval", StartDate = DateTime.Parse("04/04/2019"), Duration = 3, Progress = 50, ParentID = 5 }
};
}
}
}
}Key behaviors
When viewStartDate and viewEndDate are set to concrete Date values, the timeline rendering is restricted to the inclusive range [viewStartDate, viewEndDate].
- When
viewStartDateis set to auto:- If
projectStartDateis defined, the timeline begins atprojectStartDate. - If
projectStartDateis not defined, the earliest task start date is used as the beginning of the visible range.
- If
- When
viewEndDateis set to auto:- If
projectEndDateis defined, the timeline ends atprojectEndDate. - If
projectEndDateis not defined, the maximum task end date is used. If this end date leaves visible white‑space in the timeline area, the end date is automatically extended to fill the chart width.
- If
Note: The
ZoomToFitfeature usesprojectStartDateandprojectEndDateto fit the entire project within the available timeline viewport.
Timeline cells tooltip
In the Gantt control, you can enable or disable the mouse hover tooltip of timeline cells using the TimelineSettings.ShowTooltip property. The default value of this property is true. The following code example shows how to enable the timeline cells tooltip in Gantt.
<ejs-gantt id='Gantt' dataSource="ViewBag.DataSource" height="450px">
<e-gantt-taskfields id="TaskId" name="TaskName" startDate="StartDate" endDate="EndDate" duration="Duration" progress="Progress" child="SubTasks">
</e-gantt-taskfields>
<e-gantt-timelinesettings showTooltip="true">
</e-gantt-timelinesettings>
</ejs-gantt>public IActionResult Index()
{
ViewBag.DataSource = GanttData.ProjectNewData();
return View();
}
Show/hide weekends
The timelineSettings.showWeekend property is used to customize the timeline in the Gantt component by controlling the visibility of weekends. To exclude weekends from the timeline, set the showWeekend property to false in the timelineSettings configuration. This feature is particularly useful for focusing the timeline on working days, enhancing project management efficiency by hiding weekends from the view.
Note: To customize non-working or weekend days in the Gantt chart, refer to the workWeek documentation for detailed information.
<ejs-gantt id='Gantt' dataSource="ViewBag.dataSource" height="450px">
<e-gantt-taskfields id="TaskId" name="TaskName" startDate="StartDate"
endDate="EndDate" duration="Duration" progress="Progress" child="SubTasks">
</e-gantt-taskfields>
<e-gantt-timelinesettings showWeekend="false">
</e-gantt-timelinesettings>
</ejs-gantt>public IActionResult Index()
{
ViewBag.DataSource = ganttData();
return View();
}
public static List<GanttDataSource> ganttData()
{
List<GanttDataSource> GanttDataSourceCollection = new List<GanttDataSource>();
GanttDataSource Record1 = new GanttDataSource()
{
TaskId = 1,
TaskName = "Project initiation",
StartDate = new DateTime(2019, 04, 02),
EndDate = new DateTime(2019, 04, 21),
SubTasks = new List<GanttDataSource>(),
};
GanttDataSource Child1 = new GanttDataSource()
{
TaskId = 2,
TaskName = "Identify site location",
StartDate = new DateTime(2019, 04, 02),
Duration = 5,
Progress = 70,
};
GanttDataSource Child2 = new GanttDataSource()
{
TaskId = 3,
TaskName = "Perform soil test",
StartDate = new DateTime(2019, 04, 02),
Duration = 5,
Progress = 50,
};
GanttDataSource Child3 = new GanttDataSource()
{
TaskId = 4,
TaskName = "Soil test approval",
StartDate = new DateTime(2019, 04, 02),
Duration = 5,
Progress = 50,
};
Record1.SubTasks.Add(Child1);
Record1.SubTasks.Add(Child2);
Record1.SubTasks.Add(Child3);
GanttDataSource Record2 = new GanttDataSource()
{
TaskId = 5,
TaskName = "Project estimation",
StartDate = new DateTime(2019, 04, 02),
EndDate = new DateTime(2019, 04, 21),
SubTasks = new List<GanttDataSource>(),
};
GanttDataSource Child4 = new GanttDataSource()
{
TaskId = 6,
TaskName = "Develop floor plan for estimation",
StartDate = new DateTime(2019, 04, 02, 8, 10, 0),
Duration = 5,
Progress = 70,
};
GanttDataSource Child5 = new GanttDataSource()
{
TaskId = 7,
TaskName = "List materials",
StartDate = new DateTime(2019, 04, 02, 8, 10, 0),
Duration = 5,
Progress = 50,
};
Record2.SubTasks.Add(Child4);
Record2.SubTasks.Add(Child5);
GanttDataSourceCollection.Add(Record1);
GanttDataSourceCollection.Add(Record2);
return GanttDataSourceCollection;
}
public class GanttDataSource
{
public int TaskId { get; set; }
public string TaskName { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public int? Duration { get; set; }
public int Progress { get; set; }
public List<GanttDataSource> SubTasks { get; set; }
}Limitations
- The
showWeekendfeature does not support baselines.- The
showWeekendis not compatible with the manual task mode.- Non-working hours cannot be excluded when
showWeekendis set to false.- Holidays are not excluded from the timeline if
showWeekendis set to false.
Timeline template
In the Gantt component, you can customize timeline cells using the timelineTemplate property, allowing for the customization of HTML content within timeline cells. This feature enhances the visual appeal and enables personalized functionality.
When designing the timeline cells, you can utilize the following context properties within the template:
-
date: Defines the date of the timeline cells. -
value: Defines the formatted date value that will be displayed in the timeline cells. -
tier: Defines whether the cell is part of the top or bottom tier.
The following code example how to customize the top tier to display the week’s weather details and the bottom tier to highlight working and non-working days, with formatted text for holidays.
<ejs-gantt id='Gantt' dataSource="ViewBag.dataSource" height="450px" allowSelection="true" treeColumnIndex="1"
projectStartDate="03/31/2024" projectEndDate="04/23/2024" timelineTemplate="#TimelineTemplates">
<e-gantt-taskfields id="TaskId" name="TaskName" startDate="StartDate" endDate="EndDate" duration="Duration"
progress="Progress" dependency="Predecessor" child="SubTasks">
</e-gantt-taskfields>
<e-gantt-columns>
<e-gantt-column field="TaskId" visible=false></e-gantt-column>
<e-gantt-column field="TaskName" width="300"></e-gantt-column>
<e-gantt-column field="StartDate"></e-gantt-column>
<e-gantt-column field="EndDate"></e-gantt-column>
<e-gantt-column field="Duration"></e-gantt-column>
<e-gantt-column field="Progress"></e-gantt-column>
</e-gantt-columns>
<e-gantt-timelinesettings timelineUnitSize="100">
<e-timelinesettings-toptier unit="Week" format="MMM dd, y"></e-timelinesettings-toptier>
<e-timelinesettings-bottomtier unit="Day"></e-timelinesettings-bottomtier>
</e-gantt-timelinesettings>
<e-gantt-labelSettings leftLabel="TaskName"></e-gantt-labelSettings>
<e-gantt-splittersettings columnIndex="1"></e-gantt-splittersettings>
<e-gantt-holidays>
<e-gantt-holiday from="04/04/2019" to="04/04/2019" label="Local Holiday"></e-gantt-holiday>
<e-gantt-holiday from="04/19/2019" to="04/19/2019" label="Public holiday"></e-gantt-holiday>
</e-gantt-holidays>
</ejs-gantt>
<script type="text/x-jsrender" id="TimelineTemplates">
${if(tier == 'topTier')}
<div class="e-header-cell-label e-gantt-top-cell-text" style="width:100%;background-color: #FBF9F1 ; font-weight: bold;height: 100%;display: flex; justify-content: center ; align-items: center; "title=${date}>
<div> ${value}</div>
<div style="width:20px; height: 20px; line-height: normal; padding-left: 10px; ">
<img style="width:100%; height:100%;" src =${imagedate()} >
</div>
</div>
${/if}
${if(tier == 'bottomTier')}
<div class="e-header-cell-label e-gantt-top-cell-text" style="width:100%;background-color: ${bgColor(value,date)}; text-align: center;height: 100%;display: flex; align-items: center; font-weight: bold;justify-content: center "title=${date}>
${holidayValue(value,date)}
</div>
${/if}
</script>
<script>
const holidayValue = (value, date) => {
var ganttObj = document.getElementById("Gantt").ej2_instances[0];
const parsedDate = new Date(date);
for (let i = 0; i < ganttObj.holidays.length; i++) {
const holiday = ganttObj.holidays[i];
const fromDate = new Date(holiday.from);
const toDate = new Date(holiday.to)
if (parsedDate >= fromDate && parsedDate <= toDate) {
const options = { weekday: 'short' };
return parsedDate.toLocaleDateString('en-US', options).toLocaleUpperCase();
}
}
return value
}
const imagedate = () => {
const getImage = Math.floor(Math.random() * 5) + 1;
return "./image/" + getImage + ".svg";
}
const bgColor = (value, date) => {
if (value === "S") {
return "#7BD3EA"
}
var ganttObj = document.getElementById("Gantt").ej2_instances[0];
const parsedDate = new Date(date);
for (let i = 0; i < ganttObj.holidays.length; i++) {
const holiday = ganttObj.holidays[i];
const fromDate = new Date(holiday.from);
const toDate = new Date(holiday.to)
if (parsedDate >= fromDate && parsedDate <= toDate) {
return "#97E7E1";
}
}
return "#E0FBE2"
};
</script>public IActionResult Index()
{
ViewBag.DataSource = GanttData.ProjectNewData();
return View();
}