Annotations in Angular Linear gauge component
27 Apr 20247 minutes to read
Annotations are used to mark the specific area of interest in the Linear Gauge with text, HTML elements, or images. Any number of annotations can be added to the Linear Gauge component.
Adding annotation
To render the custom HTML elements in the Linear Gauge component, use the content
property in the e-annotation
. The annotation can be rendered either by specifying the id of the element or specifying the code to create a new element that needs to be displayed in the gauge area.
<script id='fruits' type="text/x-template">
<div id='apple'>
<img src='src/lineargauge/images/apple.png'>
</div>
</script>
import { Component } from '@angular/core';
@Component({
selector: 'app-container',
template: `
<ejs-lineargauge id="gauge-container">
<e-annotations>
<e-annotation zIndex='1' content='#fruits' x=100 y=-70></e-annotation>
</e-annotations>
</ejs-lineargauge>`
})
export class AppComponent {
ngOnInit(): void {
}
}
Customization
The following properties are used to customize the annotation.
-
zIndex
- Bring the annotation to the front or back, when annotation overlaps with another element. -
axisValue
- To place the annotation in the specified axis value with respect to the provided axis index. -
axisIndex
- To place the annotation in the specified axis with respect to the provided axis value. -
horizontalAlignment
- To place the annotation horizontally. -
verticalAlignment
- To place the annotation vertically. -
x
,y
- To place the annotation in the specified location.
Changing the z-index
To change the stack order of an annotation element, the zIndex
property of the e-annotation
can be used.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { LinearGaugeModule } from '@syncfusion/ej2-angular-lineargauge'
import { AnnotationsService } from '@syncfusion/ej2-angular-lineargauge'
import { Component } from '@angular/core';
@Component({
imports: [
LinearGaugeModule
],
providers: [ AnnotationsService ],
standalone: true,
selector: 'app-container',
template: `
<ejs-lineargauge id="gauge-container">
<e-annotations>
<e-annotation zIndex='1' content='<div id="first"><h1>Gauge</h1></div>' x=100 y=-70 ></e-annotation>
</e-annotations>
</ejs-lineargauge>`
})
export class AppComponent {
ngOnInit(): void {
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Positioning an annotation
The annotation can be placed anywhere in the Linear Gauge by setting the pixel value to the x
and y
properties in the e-annotation
.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { LinearGaugeModule } from '@syncfusion/ej2-angular-lineargauge'
import { AnnotationsService } from '@syncfusion/ej2-angular-lineargauge'
import { Component } from '@angular/core';
@Component({
imports: [
LinearGaugeModule
],
providers: [ AnnotationsService ],
standalone: true,
selector: 'app-container',
template: `
<ejs-lineargauge id="gauge-container">
<e-annotations>
<e-annotation content='<div id="first"><h1>Gauge</h1></div>' zIndex="1" x=250 y=-70></e-annotation>
</e-annotations>
</ejs-lineargauge>`
})
export class AppComponent {
ngOnInit(): void {
}
}
Alignment of annotation
The annotation can be aligned horizontally and vertically by using the horizontalAlignment
and verticalAlignment
properties respectively. The possible values can be Center, Far, Near, and None. The horizontalAlignment
and verticalAlignment
properties are not applicable when the x
and y
properties are set in the e-annotation
.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { LinearGaugeModule } from '@syncfusion/ej2-angular-lineargauge'
import { AnnotationsService } from '@syncfusion/ej2-angular-lineargauge'
import { Component } from '@angular/core';
@Component({
imports: [
LinearGaugeModule
],
providers: [ AnnotationsService ],
standalone: true,
selector: 'app-container',
template: `
<ejs-lineargauge id="gauge-container">
<e-annotations>
<e-annotation content='<div id="first"><h1>Gauge</h1></div>' zIndex="1" horizontalAlignment="Center" verticalAlignment="Center" ></e-annotation>
</e-annotations>
</ejs-lineargauge>`
})
export class AppComponent {
ngOnInit(): void {
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Multiple annotations
Multiple annotations can be added to the Linear Gauge component by adding the multiple e-annotation
in the e-annotations
and customization for the annotation can be done with the e-annotation
.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { LinearGaugeModule } from '@syncfusion/ej2-angular-lineargauge'
import { AnnotationsService } from '@syncfusion/ej2-angular-lineargauge'
import { Component } from '@angular/core';
@Component({
imports: [
LinearGaugeModule
],
providers: [ AnnotationsService ],
standalone: true,
selector: 'app-container',
template: `
<ejs-lineargauge id="gauge-container">
<e-annotations>
<e-annotation content='<div><h1 style="color:red;">Speed</h1></div>' zIndex="1" x=250 y=80>
</e-annotation>
<e-annotation content='<div><h1 style="color:blue;">Meter</h1></div>' zIndex="1" x=240 y=-100>
</e-annotation>
</e-annotations>
</ejs-lineargauge>`
})
export class AppComponent {
ngOnInit(): void {
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));