Getting Started with Blazor Linear Gauge Component (SfLinearGauge)

23 Aug 20216 minutes to read

The Blazor Linear Gauge is an ideal component for visualizing numeric values in a linear scale with features like multiple axes, different orientations, and more.

This section briefly explains how to include a Linear gauge in your Blazor server-Side application. Refer to this Getting Started with Syncfusion Blazor for Serve-Side in Visual Studio 2019 documentation for the introduction and configuring the common specifications.

Importing Syncfusion Blazor Linear Gauge component in the application

  1. Install Syncfusion.Blazor.LinearGauge NuGet package in the application using the NuGet Package Manager.

  2. You can add the client-side resources through CDN or local npm package in the <head> element of the ~/Pages/_Host.cshtml page.

<head>
    <link href="_content/Syncfusion.Blazor.Themes/bootstrap4.css" rel="stylesheet" />
    <!---CDN--->
    @*<link href="https://cdn.syncfusion.com/blazor/19.2.49/styles/bootstrap4.css" rel="stylesheet" />*@
</head>

For Internet Explorer 11 kindly refer to the polyfills. Refer the documentation for more information.

<head>
    <link href="https://cdn.syncfusion.com/blazor/19.2.49/styles/bootstrap4.css" rel="stylesheet" />
    <script src="https://github.com/Daddoon/Blazor.Polyfill/releases/download/3.0.1/blazor.polyfill.min.js"></script>
</head>

Adding a component package to the application

Open the ~/_Imports.razor file and include the Syncfusion.Blazor.LinearGauge namespace.

@using Syncfusion.Blazor.LinearGauge

Adding SyncfusionBlazor Service in Startup.cs

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.

using Syncfusion.Blazor;

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

To enable custom client-side source loading from CRG or CDN, please refer to the section about custom resources in Blazor application.

Initializing Linear Gauge component in the application

The Syncfusion Linear gauge component can be initialized in any razor page inside the ~/Pages folder. For example, the Linear Gauge component is added to the ~/Pages/Index.razor page. In a new application, if the Index.razor page has any default content template, then those content can be completely removed and the following code can be added.

@page "/"

@using Syncfusion.Blazor.LinearGauge

<SfLinearGauge>
    <LinearGaugeAxes>
        <LinearGaugeAxis>
            <LinearGaugePointers>
                <LinearGaugePointer></LinearGaugePointer>
            </LinearGaugePointers>
        </LinearGaugeAxis>
    </LinearGaugeAxes>
</SfLinearGauge>

After the successful compilation of your application, press F5 to run the application. The Blazor Linear gauge component will be rendered in the web browser as illustrated in the following screenshot.

Linear Gauge Sample

Set pointer value

Pointers are used to indicate values on an axis. You can change the pointer value using the PointerValue property in the LinearGaugePointer.

In Linear Gauge, you can configure multiple axes. On each axis, you can add a pointer.

@using Syncfusion.Blazor.LinearGauge

<SfLinearGauge>
    <LinearGaugeAxes>
        <LinearGaugeAxis>
            <LinearGaugePointers>
                <LinearGaugePointer PointerValue="40">
                </LinearGaugePointer>
            </LinearGaugePointers>
        </LinearGaugeAxis>
    </LinearGaugeAxes>
</SfLinearGauge>

Linear Gauge with pointer value

Add a title for Linear Gauge

The title can be added to the linear gauge to provide a piece of quick information to the users about the context of the rendered linear gauge. You can add the title to the linear gauge using Title property in SfLinearGauge.

@using Syncfusion.Blazor.LinearGauge

<SfLinearGauge Title="Linear Gauge">
    <LinearGaugeAxes>
        <LinearGaugeAxis>
            <LinearGaugePointers>
                <LinearGaugePointer></LinearGaugePointer>
            </LinearGaugePointers>
        </LinearGaugeAxis>
    </LinearGaugeAxes>
</SfLinearGauge>

Linear gauge with title

Add ranges in the Linear gauge

The range is used to specify a group of scale values in the gauge. We can set the range start and end using Start and End properties in the LinearGaugeRange. You can add any number of ranges for an axis using LinearGaugeRange.

@using Syncfusion.Blazor.LinearGauge

<SfLinearGauge>
    <LinearGaugeAxes>
        <LinearGaugeAxis Minimum="0" Maximum="200">
            <LinearGaugeAxisLabelStyle Format="{value}°C"></LinearGaugeAxisLabelStyle>
            <LinearGaugePointers>
                <LinearGaugePointer PointerValue="140">
                </LinearGaugePointer>
            </LinearGaugePointers>
            <LinearGaugeRanges>
                <LinearGaugeRange Start="0" End="80" Color="#ff5985"></LinearGaugeRange>
                <LinearGaugeRange Start="80" End="120" Color="#ffb133"></LinearGaugeRange>
                <LinearGaugeRange Start="120" End="140" Color="#fcde0b"></LinearGaugeRange>
                <LinearGaugeRange Start="140" End="200" Color="#27d5ff"></LinearGaugeRange>
            </LinearGaugeRanges>
        </LinearGaugeAxis>
    </LinearGaugeAxes>
</SfLinearGauge>

Linear gauge with range bar

See also