Getting started with Angular Linear gauge component
This section explains the steps required to create a simple Linear Gauge and demonstrate the basic usage of the Linear Gauge component.
Prerequisites
Ensure your development environment meets the System Requirements for Syncfusion® Angular UI Components, which covers supported Node.js, Angular, and @syncfusion/ej2-angular-lineargauge versions.
You also need a modern code editor such as Visual Studio Code, Cursor, or Syncfusion® CodeStudio.
Angular 21 Standalone Architecture: Standalone components are the default in Angular 21. This guide uses the modern standalone architecture. If you need more information about the standalone architecture, refer to the Standalone Guide.
Dependencies
Below is the list of minimum dependencies required to use the Linear Gauge component.
|-- @syncfusion/ej2-angular-lineargauge
|-- @syncfusion/ej2-angular-base
|-- @syncfusion/ej2-angular-lineargauge
|-- @syncfusion/ej2-lineargauge
|-- @syncfusion/ej2-base
|-- @syncfusion/ej2-svg-baseSetup Angular Environment
Prerequisites: Node.js (LTS) and npm must be installed before creating an Angular project.
Use the Angular CLI to create and manage Angular applications. Install the CLI with one of the following approaches depending on preference.
npm install -g @angular/cliCreate an Angular Application
Create a new Angular application with the Angular CLI:
ng new my-app
cd my-appInstall the Syncfusion® Linear Gauge package
Syncfusion® packages are published on npm under the @syncfusion scope. Angular distributions are available in two package formats:
- Ivy library distribution package (recommended)
- Angular compatibility compiler (ngcc) package (legacy)
Ivy library distribution package
From package version 20.2.36 onwards, the Syncfusion® Angular components are published as Ivy partial-compilation packages and are compatible with Angular 13 and later, including the latest Angular versions (such as Angular 21).
Install the @syncfusion/ej2-angular-lineargauge package using the following command.
npm install @syncfusion/ej2-angular-lineargaugeAngular compatibility compiled package (ngcc)
Use the legacy @ngcc-tagged package only for projects that still rely on the Angular View Engine (typically Angular 12 and earlier). Angular 13 and later do not require ngcc.
Install the @syncfusion/ej2-angular-lineargauge@ngcc package using the following command.
npm install @syncfusion/ej2-angular-lineargauge@ngccTo reference the ngcc package in package.json, add the -ngcc suffix to the package version, for example:
"@syncfusion/ej2-angular-lineargauge": "32.1.19-ngcc"Note: If the
-ngccsuffix is not specified, the Ivy package will be installed and a compatibility warning may appear when using older Angular versions.
Add the Linear Gauge component
- Open
src/app/app.component.tsand replace its contents with the following code to render the Linear Gauge component.
import { Component } from '@angular/core';
import { LinearGaugeModule } from '@syncfusion/ej2-angular-lineargauge';
@Component({
imports: [LinearGaugeModule],
standalone: true,
selector: 'app-container',
// specifies the template string for the Linear Gauge component
template: `<ejs-lineargauge id="gauge-container"></ejs-lineargauge>`
})
export class AppComponent { }-
Replace the default selector in
src/index.htmlso the new standalone component is bootstrapped.<app-container></app-container> -
Run the application in the browser with the following command.
npm start
By default, the dev server opens at http://localhost:4200/.
The following example renders a basic Linear Gauge.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { LinearGaugeModule } from '@syncfusion/ej2-angular-lineargauge'
import { GaugeTooltipService } from '@syncfusion/ej2-angular-lineargauge'
import { Component } from '@angular/core';
@Component({
imports: [
LinearGaugeModule
],
providers: [ GaugeTooltipService ],
standalone: true,
selector: 'app-container',
// specifies the template string for the linear gauge component
template: `<ejs-lineargauge id="gauge-container"></ejs-lineargauge>`
})
export class AppComponent {
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Module Injection
The Linear Gauge component is segregated into individual feature-wise services. To use a particular feature, register the matching service in the providers array of the component as shown below.
-
AnnotationsService– Required to use the Annotation feature. -
GaugeTooltipService– Required to use the Tooltip feature.
Inject the services you need in the providers section of the app.component.ts file as shown below.
The following example demonstrates injecting GaugeTooltipService to enable the tooltip on the Circular Gauge:
import { Component } from '@angular/core';
import {
LinearGaugeModule,
GaugeTooltipService
} from '@syncfusion/ej2-angular-lineargauge';
@Component({
imports: [LinearGaugeModule],
standalone: true,
selector: 'app-container',
providers: [GaugeTooltipService],
template: `<ejs-lineargauge id="gauge-container" [tooltip]="tooltip"></ejs-lineargauge>`
})
export class AppComponent {
public tooltip?: Object;
ngOnInit(): void {
this.tooltip = {
enable: true
};
}
}Note: Inject only the services required for the features you use. Injecting all services is not required and can increase the bundle size slightly.
Troubleshooting
- Feature not working (annotations, tooltip) - Ensure the matching service (
AnnotationsService,GaugeTooltipService) is registered in theprovidersarray of the host component. -
Can't bind to 'minimum'orejs-lineargauge is not a known element- Make sureLinearGaugeModuleis imported in theimportsarray of every standalone component that uses the gauge. -
npm startdoes not work - Runnpx ng serveinstead, or usenpm run start. - Compatibility warning about ngcc on Angular 12 or earlier - Install the legacy package:
npm install @syncfusion/ej2-angular-lineargauge@ngcc.