Syncfusion AI Assistant

How can I help you?

Getting started with Blazor Gantt Chart in Blazor WASM App

3 Jul 20267 minutes to read

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

Ready to streamline your Blazor development?
Discover the full potential of Blazor components with 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, CodeStudio and more. Explore AI Coding Assistants

Create a new Blazor WebAssembly (Standalone) App

Create a Blazor WebAssembly App using Visual Studio via Microsoft Templates or the Blazor Extension.

Run the following command to create a new Blazor WebAssembly App.

dotnet new blazorwasm -o BlazorApp
cd BlazorApp

Alternatively, create a Blazor WebAssembly App using Visual Studio Code via Microsoft Templates or the Blazor Extension, or the C# Dev Kit extension.

Run the following command to create a new Blazor WebAssembly App.

dotnet new blazorwasm -o BlazorApp
cd BlazorApp

Install the required Blazor packages

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

  1. Go to Tools → NuGet Package Manager → Manage NuGet Packages for Solution.
  2. Search the required NuGet packages (Syncfusion.Blazor.Gantt and Syncfusion.Blazor.Themes) and install them.

Alternatively, you can install the same packages using the Package Manager Console with the following commands.

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

Open the terminal and run the following commands.

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

Open the command prompt and run the following commands.

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

Register the Blazor service

Open the Program.cs file in Blazor WebAssembly App and register the Blazor service.

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

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

Add Blazor Gantt Chart component

Open a Razor file located in the ~/Pages/*.razor (for example, Home.razor) and add the Blazor Gantt Chart component inside the razor file.

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

Run the application

Press Ctrl+F5 (Windows) or +F5 (macOS) to launch the application. The Blazor Gantt Chart component will render in your default web browser.

Open the terminal and run the following command.

dotnet run

Open the command prompt and run the following command.

dotnet run

NOTE

Looking for the full Blazor Gantt Chart component overview, features, pricing, and documentation? Visit the Blazor Gantt Chart page.

See also

  1. Getting Started with Blazor for Client-Side in .NET Core CLI
  2. Getting Started with Blazor for Server-Side in Visual Studio
  3. Getting Started with Blazor for Server-Side in .NET Core CLI