Getting started with Blazor Gantt Chart in Blazor server app
18 Nov 20189 minutes to read
This section briefly explains about how to include Syncfusion® Blazor Gantt Chart component in your Blazor server app using Visual Studio and Visual Studio Code.
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 App in Visual Studio
Create a Blazor Server App by using the Blazor Web App template in Visual Studio via Microsoft Templates or the Syncfusion® Blazor Extension. For detailed instructions, refer to the Blazor Server App Getting Started documentation.
Install Syncfusion® Blazor packages
Once the project is created, install Syncfusion.Blazor.Gantt and Syncfusion.Blazor.Themes NuGet packages in your project using the NuGet Package Manager.
- Go to Tools → NuGet Package Manager → Manage NuGet Packages for Solution
- Search for
Syncfusion.Blazor.Ganttand install the latest version - Search for
Syncfusion.Blazor.Themesand install the latest version
Alternatively, run the following commands in the Package Manager Console:
Install-Package Syncfusion.Blazor.Gantt -Version 34.1.29
Install-Package Syncfusion.Blazor.Themes -Version 34.1.29Prerequisites
Create a new Blazor App in Visual Studio Code
Create a Blazor Server App using Visual Studio Code via Microsoft Templates or the Syncfusion® Blazor Extension. For detailed instructions, refer to the Blazor Server App Getting Started documentation.
Alternatively, create a Server application by using the following command in the integrated terminal (Ctrl+`):
dotnet new blazor -o BlazorApp -int Server
cd BlazorAppInstall Syncfusion® Blazor packages
Then, 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 34.1.29
dotnet add package Syncfusion.Blazor.Themes --version 34.1.29Prerequisites
Install the latest version of .NET SDK. If the .NET SDK is already installed, determine the installed version by running the following command in a command prompt (Windows), terminal (macOS), or command shell (Linux).
dotnet --versionCreate a Blazor Server App
Run the following command to create a new Blazor Server App in a command prompt (Windows) or terminal (macOS) or command shell (Linux). For detailed instructions, refer to the Blazor Server App Getting Started documentation.
dotnet new blazor -o BlazorApp -int Server
cd BlazorAppInstall Syncfusion® Blazor packages
Then, 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 34.1.29
dotnet add package Syncfusion.Blazor.Themes --version 34.1.29NOTE
Configure the appropriate Interactive render mode and Interactivity location while creating a Blazor Server 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 Server App.
....
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 ~/Components/App.razor file.
- Add the stylesheet reference inside the
<head>tag of theApp.razorfile. - Add the script reference inside the
<body>tag of theApp.razorfile.
<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 Blazor application. Also, check out the Adding Script Reference topic to learn different approaches for adding script references in Blazor application.
Add Syncfusion® Blazor Gantt Chart component
Add the Syncfusion® Blazor Gantt Chart component in the ~/Components/Pages/Home.razor file. If the interactivity location is set to Per page/component, define a render mode at the top of the ~Pages/Home.razor file.
NOTE
If the Interactivity Location is set to
Global, the render mode is automatically configured in theApp.razorfile by default.
@* Define the desired render mode here *@
@rendermode InteractiveServer@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 {
public List<TaskData>? TaskCollection { get; set; }
protected override void OnInitialized()
{
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; }
}
public static List<TaskData> GetTaskCollection()
{
List<TaskData> Tasks = new List<TaskData>()
{
new TaskData() { TaskId = 1, TaskName = "Project initiation", StartDate = new DateTime(2026, 01, 05), EndDate = new DateTime(2026, 01, 08), },
new TaskData() { TaskId = 2, TaskName = "Identify Site location", StartDate = new DateTime(2026, 01, 05), Duration = "0", Progress = 30, ParentId = 1, },
new TaskData() { TaskId = 3, TaskName = "Perform soil test", StartDate = new DateTime(2026, 01, 05), EndDate = new DateTime(2026, 01, 08), Progress = 40, ParentId = 1, },
new TaskData() { TaskId = 4, TaskName = "Soil test approval", StartDate = new DateTime(2026, 01, 05), Duration = "0", Progress = 30, ParentId = 1, },
new TaskData() { TaskId = 5, TaskName = "Project estimation", StartDate = new DateTime(2026, 01, 05), EndDate = new DateTime(2026, 01, 10), },
new TaskData() { TaskId = 6, TaskName = "Develop floor plan for estimation", StartDate = new DateTime(2026, 01, 07), EndDate = new DateTime(2026, 01, 09), Progress = 30, ParentId = 5, },
new TaskData() { TaskId = 7, TaskName = "List materials", StartDate = new DateTime(2026, 01, 07), EndDate = new DateTime(2026, 01, 09), Progress = 40, ParentId = 5, },
new TaskData() { TaskId = 8, TaskName = "Estimation approval", StartDate = new DateTime(2026, 01, 07), Duration = "0", Progress = 30, ParentId = 5, }
};
return Tasks;
}
}Run the application
Visual Studio:
- Press Ctrl+F5 (Windows) or ⌘+F5 (macOS) to launch the application. The Blazor Gantt Chart component will render in your default web browser.
Visual Studio Code or .NET CLI:
- Open a terminal in the project directory and run the following command:
dotnet run - The application will start and display in your default web browser.