Articles in this section
Category / Section

How to get started easily with Syncfusion angular 6 Gantt Chart?

3 mins read

The Essential JS2 Angular Gantt control is designed to visualize and edit the project schedule and track the project progress. It helps to organize and schedule the projects and you can update the project schedule through interactions like editing, dragging and resizing. In this knowledge base we are going to provide details about create and integrate an Angular 6 Gantt chart Application with a minimal code configuration.

 

Prerequisites

Before start, we need following items to create Angular Gantt in Angular 6 application

Installation and application creation

  • Install Angular cli 6 using following command.
    npm install -g @angular/cli@6.1.1
    
  • Create an Angular 6 application using Angular cli.
    ng new gantt-angular6
    cd gantt-angular6
    
  • Install the ej2-angular-gantt package through the npm install command.
    npm install @syncfusion/ej2-angular-gantt --save 
    
  • Serve the Angular 6 application using following command
    ng serve --open
    

Listen the application in localhost:4200. Your application will serve in browser. Refer the below example screenshot for Angular 6 version.Angular application startup page to get start with Syncfusion Gantt control.

Adding Angular 6 Gantt chart

You can add the Angular 6 Gantt component by using `ejs-gantt` directive and the attributes used within this tag allows you to define other Gantt functionalities.

  • Import the GanttModule in app.module.ts file from the ej2-angular-gantt package.
  • The next step in Angular Gantt Chart creation is to import and inject the other required modules within providers section of app.module.ts

[app.module.ts]

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { GanttModule } from '@syncfusion/ej2-angular-gantt';
import { AppComponent } from './app.component';
 
 
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    GanttModule
  ],
  bootstrap: [AppComponent]
})
export class AppModule { } 
  • You should refer the CSS file for Angular Gantt in style.CSS     
    @import '../node_modules/@syncfusion/ej2-base/styles/material.css';
    @import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
    @import '../node_modules/@syncfusion/ej2-calendars/styles/material.css';
    @import '../node_modules/@syncfusion/ej2-dropdowns/styles/material.css';
    @import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
    @import '../node_modules/@syncfusion/ej2-lists/styles/material.css';
    @import '../node_modules/@syncfusion/ej2-layouts/styles/material.css';
    @import '../node_modules/@syncfusion/ej2-navigations/styles/material.css';
    @import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
    @import '../node_modules/@syncfusion/ej2-richtexteditor/styles/material.css';
    @import '../node_modules/@syncfusion/ej2-grids/styles/material.css';
    @import '../node_modules/@syncfusion/ej2-treegrid/styles/material.css';
    @import '../node_modules/@syncfusion/ej2-gantt/styles/material.css';
     
    
  • Add the Angular Gantt component in app.component.html.
    <ejs-gantt></ejs-gantt>
    
  • Now, define the row data for this Gantt in app.component.ts. Here, the JSON data is used for the Gantt.
    export class AppComponent implements OnInit {
        public data: Object[];
        public taskfield: Object; 
        ngOnInit() {
            this.data = [{
                TaskID: 1,
                TaskName: 'Product Concept',
                StartDate: new Date('04/02/2019'),
                EndDate: new Date('04/21/2019'),
                subtasks: [{
                    TaskID: 2,
                    TaskName: 'Defining the product and its usage',
                    StartDate: new Date('04/02/2019'),
                    Duration: 5,
                    Progress: 30
                },
     
                ]
            }, ];
            this.taskfield = {
                id: 'TaskID',
                name: 'TaskName',
                startDate: 'StartDate',
                endDate: 'EndDate',
                child: 'subtasks'
            };
        }
    } 
    
  • After defining the data source for Gantt, define the data source and task fields in app.component.html file.
    <ejs-gantt id="GanttSample" 
      [dataSource]="data" 
      height= "450px"
      width="800px"
      [taskFields]= "taskfield">
    </ejs-gantt>
    
  • Now serve the application using following command.
     ng serve --open
    

Once all the files are compiled successfully. It will serve the site at localhost:4200

The following screenshot illustrates this.Angular application  Gantt control startup page

Enabling features

Till now we have studied how to integrate Gantt control in Angular 6 application. This section describes how to inject Gantt services and enable its features. Before enable Gantt features, we need to define their services in app.module.ts.

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { GanttModule, ResizeService, SortService, FilterService, SelectionService, ReorderService,
  EditService, DayMarkersService, ToolbarService } from '@syncfusion/ej2-angular-gantt';
 
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    GanttModule
  ],
  providers: [ ResizeService, SortService, FilterService, SelectionService, ReorderService,
  EditService, DayMarkersService, ToolbarService],
  bootstrap: [AppComponent]
})
export class AppModule { } 

 

Filtering

By declaring FilterService in app.module.ts. You can use filtering functionalities in Gantt. To enable filter, we need to define allowFiltering as true.

<ejs-gantt id='GanttSample' 
  [dataSource]='data' 
  height= '450px' 
  allowFiltering = 'true'
  [taskFields]= 'taskfield'>
</ejs-gantt>

 

After enabling the, filter menu UI will be obtained as follows.

Angular application  Gantt control with Filtering UI

Event Markers

By declaring DayMarkersService in app.module.ts, You can mark special events in project. As this is an object array you can mark more than one events in the Gantt chart.

<ejs-gantt id='GanttSample' 
  [dataSource]='data' 
  height= '450px' 
  allowFiltering = 'true'
  [eventMarkers] = 'eventMarkers'
  [taskFields]= 'taskfield'>
</ejs-gantt>

 

TS

@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
    public data: Object[];
    public eventMarkers: any;
    ngOnInit() {
        this.eventMarkers = [{
            day: '04/04/2019',
            label: 'Research phase'
        }];
    }
}

After defining day markers. UI will be obtained as follows. Angular application  Gantt control with event markers

Summary

In this GitHub repository, the application prepared from the above steps has been committed, and it is readily runnable. Also, you can check our Angular Gantt features from this page.

If you have any queries or require clarifications. Please let us know in comments below. You can also contact us through our Support forum or Direct-Trac. We are happy to assist you!

 

 

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied