Syncfusion AI Assistant

How can I help you?

Getting Started with Blazor Gantt Chart Component in Blazor Web App

22 May 20269 minutes to read

This section briefly explains about how to include Syncfusion® Blazor Gantt Chart component in your Blazor Web App using Visual Studio, Visual Studio Code, and the .NET CLI.

Ready to streamline your Syncfusion® Blazor development?
Discover the full potential of Syncfusion® Blazor components with Syncfusion® AI Coding Assistants. Effortlessly integrate, configure, and enhance your projects with intelligent, context-aware code suggestions, streamlined setups, and real-time insights—all seamlessly integrated into your preferred AI-powered IDEs like VS Code, Cursor, Syncfusion® CodeStudio and more. Explore Syncfusion® AI Coding Assistants

Prerequisites

Create a new Blazor Web App

Create a Blazor Web App using Visual Studio via Microsoft Templates or the Syncfusion® Blazor Extension. For detailed instructions, refer to the Blazor Web App Getting Started documentation.

Install Syncfusion® Blazor packages

Install Syncfusion.Blazor.Gantt and Syncfusion.Blazor.Themes NuGet packages in your project using the NuGet Package Manager.

  1. Go to Tools → NuGet Package Manager → Manage NuGet Packages for Solution
  2. Search for Syncfusion.Blazor.Gantt and install the latest version
  3. Search for Syncfusion.Blazor.Themes and install the latest version

Alternatively, run the following commands in the Package Manager Console:

Install-Package Syncfusion.Blazor.Gantt -Version 33.2.3
Install-Package Syncfusion.Blazor.Themes -Version 33.2.3

If using the WebAssembly or Auto render modes in the Blazor Web App, install these packages in the client project.

Prerequisites

Create a new Blazor Web App

Create a Blazor Web App using Visual Studio Code via Microsoft Templates or the Syncfusion® Blazor Extension. For detailed instructions, refer to the Blazor Web App Getting Started documentation.

For example, in a Blazor Web App with the Auto interactive render mode, use the following commands in the integrated terminal (Ctrl+`):

dotnet new blazor -o BlazorWebApp -int Auto
cd BlazorWebApp
cd BlazorWebApp.Client

Install Syncfusion® Blazor packages

Install Syncfusion.Blazor.Gantt and Syncfusion.Blazor.Themes NuGet packages in your project using the integrated terminal.

Run the following commands in the integrated terminal (Ctrl+`):

dotnet add package Syncfusion.Blazor.Gantt --version 33.2.3
dotnet add package Syncfusion.Blazor.Themes --version 33.2.3

If using the WebAssembly or Auto render modes in the Blazor Web App, run these commands in the client project directory.

Prerequisites

Install the latest version of .NET SDK. If you previously installed the SDK, determine the installed version by executing the following command in a command prompt (Windows) or terminal (macOS) or command shell (Linux).

dotnet --version

Create a Blazor Web App

Run the following command to create a new Blazor Web App in a command prompt (Windows) or terminal (macOS) or command shell (Linux). For detailed instructions, refer to the Blazor Web App Getting Started documentation.

For example, in a Blazor Web App with the Auto interactive render mode, use the following commands:

dotnet new blazor -o BlazorApp -int Auto
cd BlazorApp
cd BlazorApp.Client

Install Syncfusion® Blazor packages

Install Syncfusion.Blazor.Gantt and Syncfusion.Blazor.Themes NuGet packages using the .NET CLI.

Run the following commands in your command prompt, terminal, or command shell:

dotnet add package Syncfusion.Blazor.Gantt --version 33.2.3
dotnet add package Syncfusion.Blazor.Themes --version 33.2.3

If using the WebAssembly or Auto render modes in the Blazor Web App, run these commands in the client project directory.

NOTE

Configure the appropriate Interactive render mode and Interactivity location while creating a Blazor Web App. For detailed information, refer to the interactive render mode documentation.

NOTE

All Syncfusion Blazor packages are available on nuget.org. See the NuGet packages topic for details.

Register Syncfusion® Blazor service

Register the Syncfusion® Blazor Service in the Program.cs file of your Blazor Web App.

....
using Syncfusion.Blazor;
....
builder.Services.AddSyncfusionBlazor();
....

NOTE

If the Interactive Render Mode is set to WebAssembly or Auto, register the Syncfusion® Blazor service in Program.cs files of both the server and client projects in your Blazor Web App.

Add stylesheet and script resources

The theme stylesheet and script can be accessed from NuGet through Static Web Assets. Include the stylesheet and script references in the ~/Components/App.razor file.

  • Add the stylesheet reference inside the <head> tag of the App.razor file.
  • Add the script reference inside the <body> tag of the App.razor file.
<link href="_content/Syncfusion.Blazor.Themes/fluent2.css" rel="stylesheet" />
....
<script src="_content/Syncfusion.Blazor.Core/scripts/syncfusion-blazor.min.js" type="text/javascript"></script>

NOTE

Check out the Blazor Themes topic to discover various methods (Static Web Assets, CDN, and CRG) for referencing themes in your Blazor application. Also, check out the Adding Script Reference topic to learn different approaches for adding script references in your Blazor application.

Add Syncfusion® Blazor Gantt Chart component

Add the Syncfusion® Blazor Gantt Chart component in the ~/Components/Pages/*.razor file. If the interactivity location is set to Per page/component in the Web App, define a render mode at the top of the ~/Pages/*.razor file. (For example, InteractiveServer, InteractiveWebAssembly or InteractiveAuto).

NOTE

If the Interactivity Location is set to Global with Auto or WebAssembly, the render mode is automatically configured in the App.razor file by default.

@* Define the desired render mode here *@
@rendermode InteractiveAuto
@using Syncfusion.Blazor.Gantt

<SfGantt DataSource="@TaskCollection" Height="450px" Width="700px">
    <GanttTaskFields Id="TaskID" Name="TaskName" StartDate="StartDate" EndDate="EndDate" Duration="Duration" Progress="Progress" ParentID="ParentID">
    </GanttTaskFields>
</SfGantt>

@code{
    private List<TaskData> TaskCollection { get; set; }
    protected override void OnInitialized()
    {
        this.TaskCollection = GetTaskCollection();
    }

    public class TaskData
    {
        public int TaskID { get; set; }
        public string TaskName { get; set; }
        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }
        public string Duration { get; set; }
        public int Progress { get; set; }
        public int? ParentID { get; set; }
    }

    private static List<TaskData> GetTaskCollection()
    {
        List<TaskData> Tasks = new List<TaskData>()
        {
            new TaskData() { TaskID = 1, TaskName = "Project initiation", StartDate = new DateTime(2022, 01, 04), EndDate = new DateTime(2022, 01, 07), },
            new TaskData() { TaskID = 2, TaskName = "Identify Site location", StartDate = new DateTime(2022, 01, 04), Duration = "0", Progress = 30, ParentID = 1, },
            new TaskData() { TaskID = 3, TaskName = "Perform soil test", StartDate = new DateTime(2022, 01, 04), Duration = "4", Progress = 40, ParentID = 1, },
            new TaskData() { TaskID = 4, TaskName = "Soil test approval", StartDate = new DateTime(2022, 01, 04), Duration = "0", Progress = 30, ParentID = 1, },
            new TaskData() { TaskID = 5, TaskName = "Project estimation", StartDate = new DateTime(2022, 01, 06), EndDate = new DateTime(2022, 01, 10), },
            new TaskData() { TaskID = 6, TaskName = "Develop floor plan for estimation", StartDate = new DateTime(2022, 01, 06), Duration = "3", Progress = 30, ParentID = 5, },
            new TaskData() { TaskID = 7, TaskName = "List materials", StartDate = new DateTime(2022, 01, 06), Duration = "3", Progress = 40, ParentID = 5, },
            new TaskData() { TaskID = 8, TaskName = "Estimation approval", StartDate = new DateTime(2022, 01, 06), Duration = "0", Progress = 30, ParentID = 5, }
        };
        return Tasks;
    }
}

See also

  1. Getting Started with Syncfusion® Blazor for client-side in .NET Core CLI
  2. Getting Started with Syncfusion® Blazor for client-side in Visual Studio
  3. Getting Started with Syncfusion® Blazor for server-side in .NET Core CLI