Search results

Getting started with Blazor HeatMap Chart component

08 Apr 2021 / 4 minutes to read

This section briefly explains how to include a HeatMap Chart in your Blazor Server-Side application. Refer to the Getting Started with Syncfusion Blazor for Server-Side in Visual Studio 2019 page for the introduction and configuring the common specifications.

Importing Syncfusion Blazor component in the application

Using Syncfusion.Blazor NuGet Package [New standard]

  1. Install Syncfusion.Blazor.HeatMap NuGet package to the application by using the NuGet Package Manager. Refer to the Individual NuGet Packages section for the available NuGet packages. nuget explorer
  2. Search Syncfusion.Blazor.HeatMap keyword in the Browse tab and install Syncfusion.Blazor.HeatMap NuGet package in the application. nuget-heatmapchart
  3. Once the installation process is completed, the Syncfusion Blazor HeatMap package will be installed in the project.

    Warning: Syncfusion.Blazor package should not be installed along with individual NuGet packages. Hence, you have to add the below Syncfusion.Blazor.Themes static web assets (styles) in the application.

  4. You can add the client-side style resources using NuGet package to the <head> element of the ~/wwwroot/index.html page in Blazor WebAssembly app or ~/Pages/_Host.cshtml page in Blazor Server app.
Copied to clipboard
<head>
    ....
    ....
   <link href="_content/Syncfusion.Blazor.Themes/bootstrap4.css" rel="stylesheet" />
</head>

Warning: If you prefer the above new standard (individual NuGet packages), then skip this section. Using both old and new standards in the same application will throw ambiguous compilation errors.

Using Syncfusion.Blazor NuGet Package [Old standard]

  1. Install Syncfusion.Blazor NuGet package to the application by using the NuGet Package Manager.Right-click the project and then select Manage NuGet Packages. nuget explorer
  2. Search Syncfusion.Blazor keyword in the Browse tab and install Syncfusion.Blazor NuGet package in the application. select-nuget
  3. Once the installation process is completed, the Syncfusion Blazor package will be installed in the project.
  4. You can add the client-side style resources using NuGet package to the <head> element of the ~/wwwroot/index.html page in Blazor WebAssembly app or ~/Pages/_Host.cshtml page in Blazor Server app.

    Note: You can also add the client-side style resources through CDN.

Copied to clipboard
<head>
    ....
    ....
    <link href="_content/Syncfusion.Blazor/styles/bootstrap4.css" rel="stylesheet" />
</head>
Copied to clipboard
<head>
    <link href="https://cdn.syncfusion.com/blazor/18.4.42/styles/bootstrap4.css" rel="stylesheet" />
</head>
  • For Internet Explorer 11 kindly refer the polyfills. Refer the documentation for more information.
Copied to clipboard
<head>
<link href="_content/Syncfusion.Blazor/styles/bootstrap4.css" rel="stylesheet" />
<script src="https://github.com/Daddoon/Blazor.Polyfill/releases/download/3.0.1/blazor.polyfill.min.js"></script>
</head>

Add Syncfusion Blazor service in Startup.cs (Server-side application)

Open the Startup.cs file and add services required by Syncfusion components using services.AddSyncfusionBlazor() method. Add this method in the ConfigureServices function as follows.

Copied to clipboard
using Syncfusion.Blazor;

namespace BlazorApplication
{
public class Startup
{
    ....
    ....
    public void ConfigureServices(IServiceCollection services)
    {
        ....
        ....
        services.AddSyncfusionBlazor();
    }
}
}

Add Syncfusion Blazor service in Program.cs (Client-side application)

Open the Program.cs file and add services required by Syncfusion components using builder.services.AddSyncfusionBlazor() method. Add this method in the Main function as follows.

Copied to clipboard
using Syncfusion.Blazor;

namespace BlazorApplication
{
public class Program
{
    public static async Task Main(string[] args)
    {
        ....
        ....
        builder.Services.AddSyncfusionBlazor();
    }
}
}

Note: To enable custom client side resource loading from CRG or CDN. You need to disable resource loading by AddSyncfusionBlazor(true) and load the scripts to the <head> element of the ~/wwwroot/index.html page in Blazor WebAssembly app or ~/Pages/_Host.cshtml page in Blazor Server app.

Copied to clipboard
<head>
    <script src="https://cdn.syncfusion.com/blazor/18.4.42/syncfusion-blazor.min.js"></script>
</head>

Adding component package to the application

Open ~/_Imports.razor file and import the Syncfusion.Blazor.HeatMap package.

Copied to clipboard
@using Syncfusion.Blazor
@using Syncfusion.Blazor.HeatMap

Adding HeatMap component to the application

Now, add the Syncfusion Blazor HeatMap component in any web page razor in the Pages folder. For example, the HeatMap component is added in the ~/Pages/Index.razor page.

Copied to clipboard
@using Syncfusion.Blazor.HeatMap

<SfHeatMap DataSource="@HeatMapData">
<HeatMapTitleSettings Text="Sales Revenue per Employee (in 1000 US$)"></HeatMapTitleSettings>
<HeatMapCellSettings ShowLabel="true" TileType="CellType.Rect"></HeatMapCellSettings>
</SfHeatMap>

@code{
int[,] GetDefaultData()
{
    int[,] dataSource = new int[,]
    {
        {52, 65, 67, 45, 37, 52},
        {68, 52, 63, 51, 30, 51},
        {7, 16, 47, 47, 88, 6},
        {66, 64, 46, 40, 47, 41},
        {14, 46, 97, 69, 69, 3},
        {54, 46, 61, 46, 40, 39}
    };
    return dataSource;
}
public object HeatMapData { get; set; }
protected override void OnInitialized()
{
    HeatMapData = GetDefaultData();
}
}

Heatmap Sample

Run the application

After successful compilation of your application, simply press F5 to run the application.

See Also

Getting Started with Syncfusion Blazor for Client-Side in .NET Core CLI

Getting Started with Syncfusion Blazor for Client-Side in Visual Studio 2019

Getting Started with Syncfusion Blazor for Server-Side in .NET Core CLI