Search results

Render timeline from 1 to 365 days in JavaScript Gantt control

14 Apr 2021 / 2 minutes to read

Gantt chart contains different types of in-built timeline view modes and it can be defined by using timelineViewMode property and also we can customize the timescale mode of top tier and bottom tier by using topTier.unit and bottomTier.unit properties. Timeline tier’s unit can be defined by using unit property and format property was used to define date format of timeline cell and formatter property was used to define custom method to format the date value of timeline cell.

In the bottomTier.unit timescale mode, it is possible to display timeline from 1 to 365 days by making use of the formatter in the timelineSettings property. The following example shows how to use the formatter method for timeline cells.

Copied to clipboard
import { Gantt } from '@syncfusion/ej2-gantt';
import { GanttData } from 'datasource.ts';

let gantt: Gantt = new Gantt({
    dataSource: GanttData,
    taskFields: {
        id: 'TaskID',
        name: 'TaskName',
        startDate: 'StartDate',
        duration: 'Duration',
        progress: 'Progress',
        child: 'subtasks'
    timelineSettings: { 
        timelineUnitSize: 50, 
        topTier: { 
            unit: "Month", 
            format: "MMM dd, y" 
        bottomTier: { 
            unit: "Day", 
            formatter: date => { 
                let presentDate = new Date( 
                var start = new Date(presentDate.getFullYear(), 0, 0); 
                var diff = Number(presentDate) - Number(start); 
                var oneDay = 1000 * 60 * 60 * 24; 
                var day = Math.floor(diff / oneDay); 
                return day; 
    projectStartDate: new Date("01/01/2019"),
    projectEndDate: new Date("01/01/2020")

Copied to clipboard
<!DOCTYPE html>
<html lang="en">

    <title>EJ2 Gantt</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript Gantt Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
	<link href="" rel="stylesheet" type="text/css"/>
    <script src=""></script>
    <script src="systemjs.config.js"></script>

    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='Gantt'></div>