Getting Started with Blazor Bullet Chart Component in Blazor WASM App

7 Jul 20266 minutes to read

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

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 package

Install the Syncfusion.Blazor.BulletChart NuGet package. 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 package (Syncfusion.Blazor.BulletChart) and install it.

Alternatively, you can install the same package using the Package Manager Console with the following command.

Install-Package Syncfusion.Blazor.BulletChart -Version 34.1.29

Open the terminal and run the following command.

dotnet add package Syncfusion.Blazor.BulletChart -v 34.1.29

Open the command prompt and run the following command.

dotnet add package Syncfusion.Blazor.BulletChart -v 34.1.29

Add import namespaces

After the packages are installed, open the ~/_Imports.razor file and import the Syncfusion.Blazor and Syncfusion.Blazor.Charts namespaces.

@using Syncfusion.Blazor
@using Syncfusion.Blazor.Charts

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

The script can be accessed from NuGet through Static Web Assets. Include the script references in the ~wwwroot/index.html file.

<script src="_content/Syncfusion.Blazor.Core/scripts/syncfusion-blazor.min.js" type="text/javascript"></script>

Add Blazor Bullet Chart component

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

@page "/"

<SfBulletChart DataSource="@BulletChartData" ValueField="FieldValue" TargetField="TargetValue" Minimum="0" Maximum="300" Interval="50">
</SfBulletChart>

@code
{
    public class ChartData
    {
        public double FieldValue { get; set; }
        public double TargetValue { get; set; }
    }
    public List<ChartData> BulletChartData = new List<ChartData>
    {
        new ChartData { FieldValue = 270, TargetValue = 250 }
    };
}

Run the application

Press Ctrl+F5 (Windows) or +F5 (macOS) to launch the application. The Blazor Bullet 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
Blazor Bullet Chart Component

NOTE

View Sample in GitHub.

Adding title

Add a title by using the Title property in the Bullet Chart to provide quick information to the user about the data plotted in the component.

<SfBulletChart DataSource="@BulletChartData" ValueField="FieldValue" TargetField="TargetValue" Minimum="0" Maximum="300" Interval="50" Title="Revenue">
</SfBulletChart>
Blazor Bullet Chart with Title

Adding ranges

Add ranges by using the BulletChartRangeCollection to measure the qualitative state by observing the distance between each range.

<SfBulletChart DataSource="@BulletChartData" ValueField="FieldValue" TargetField="TargetValue" Minimum="0" Maximum="300" Interval="50" Title="Revenue">
    <BulletChartRangeCollection>
        <BulletChartRange End=150> </BulletChartRange>
        <BulletChartRange End=250></BulletChartRange>
        <BulletChartRange End=300></BulletChartRange>
    </BulletChartRangeCollection>
</SfBulletChart>
Adding Range in Blazor Bullet Chart

Adding tooltip

Use the tooltip to show the measured values by setting the Enable property to true in the BulletChartTooltip.

<SfBulletChart DataSource="@BulletChartData" ValueField="FieldValue" TargetField="TargetValue" Minimum="0" Maximum="300" Interval="50" Title="Revenue">
    <BulletChartTooltip TValue="ChartData" Enable="true"></BulletChartTooltip>
    <BulletChartRangeCollection>
        <BulletChartRange End=150> </BulletChartRange>
        <BulletChartRange End=250></BulletChartRange>
        <BulletChartRange End=300></BulletChartRange>
    </BulletChartRangeCollection>
</SfBulletChart>
Blazor Bullet Chart displays ToolTip

See also

  1. Getting Started with Blazor for server-side in .NET Core CLI