Timeline

11 Jun 202424 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();
}

Alt text

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

Alt text

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

Alt text

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

Alt text

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

Alt text

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

Alt text

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