User interaction in Angular Linear gauge component
27 Apr 202413 minutes to read
Tooltip
Linear Gauge displays the details about a pointer value through tooltip
, when the mouse hovers over the pointer. To enable the tooltip, set enable
property as true and and inject the GaugeTooltipService in the providers.
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, OnInit } from '@angular/core';
@Component({
imports: [
LinearGaugeModule
],
providers: [ GaugeTooltipService ],
standalone: true,
selector: 'app-container',
template: `
<ejs-lineargauge id='tooltipContainer' style='display:block;' [tooltip]='tooltip'>
<e-axes>
<e-axis>
<e-pointers>
<e-pointer value=80></e-pointer>
</e-pointers>
</e-axis>
</e-axes>
</ejs-lineargauge>`
})
export class AppComponent implements OnInit {
public tooltip?:Object;
ngOnInit(): void {
this.tooltip = {
enable: true
};
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Tooltip format
Tooltip in the Linear Gauge control can be formatted using the format
property in tooltip
. It is used to render the tooltip in certain format or to add a user-defined unit in the tooltip. By default, the tooltip shows the pointer value only. In addition to that, more information can be added in the tooltip. For example, the format {value}km shows pointer value with kilometer unit in the tooltip.
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, OnInit } from '@angular/core';
@Component({
imports: [
LinearGaugeModule
],
providers: [ GaugeTooltipService ],
standalone: true,
selector: 'app-container',
template: `
<ejs-lineargauge id="gauge-container" style='display:block;' [tooltip]='tooltip'>
<e-axes>
<e-axis>
<e-pointers>
<e-pointer value=80></e-pointer>
</e-pointers>
</e-axis>
</e-axes>
</ejs-lineargauge>`
})
export class AppComponent implements OnInit {
public tooltip?:Object;
ngOnInit(): void {
this.tooltip = {
enable: true,
format: '{value}km'
};
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Tooltip Template
The HTML element can be rendered in the tooltip of the Linear Gauge using the template
property in tooltip
. The ${value} can be used as placeholders in the HTML element to display the pointer values of the corresponding axis.
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, OnInit } from '@angular/core';
@Component({
imports: [
LinearGaugeModule
],
providers: [ GaugeTooltipService ],
standalone: true,
selector: 'app-container',
template: `
<ejs-lineargauge id="gauge-container" style='display:block;' [tooltip]='tooltip'>
<e-axes>
<e-axis>
<e-pointers>
<e-pointer value=80></e-pointer>
</e-pointers>
</e-axis>
</e-axes>
</ejs-lineargauge>`
})
export class AppComponent implements OnInit {
public tooltip?:Object;
ngOnInit(): void {
this.tooltip = {
enable: true,
//tooltip template for Linear gauge
template: '<div>Pointer: 80 </div>'
};
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Customize the appearance of the tooltip
The tooltip can be customized using the following properties in tooltip
.
-
fill
- To fill the color for tooltip. -
enableAnimation
- To enable or disable the tooltip animation. -
border
- To set the border color and width of the tooltip. -
textStyle
- To customize the style of the text in tooltip. -
showAtMousePosition
- To show the tooltip at the mouse position.
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, OnInit } from '@angular/core';
@Component({
imports: [
LinearGaugeModule
],
providers: [ GaugeTooltipService ],
standalone: true,
selector: 'app-container',
template: `
<ejs-lineargauge id="gauge-container" style='display:block;' [tooltip]='tooltip'>
<e-axes>
<e-axis>
<e-pointers>
<e-pointer value=80></e-pointer>
</e-pointers>
</e-axis>
</e-axes>
</ejs-lineargauge>`
})
export class AppComponent implements OnInit {
public tooltip?:Object;
ngOnInit(): void {
this.tooltip = {
enable: true,
fill: '#e5bcbc',
border: {
color: '#d80000',
width: 2
}
};
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Positioning the tooltip
The tooltip is positioned at the End of the pointer. To change the position of the tooltip at the start, or center of the pointer, set the position
property to Start or Center.
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, OnInit } from '@angular/core';
@Component({
imports: [
LinearGaugeModule
],
providers: [ GaugeTooltipService ],
standalone: true,
selector: 'app-container',
template: `
<ejs-lineargauge id="gauge-container" style='display:block;' [tooltip]='tooltip'>
<e-axes>
<e-axis>
<e-pointers>
<e-pointer value=50 type="Bar" color="blue"></e-pointer>
</e-pointers>
</e-axis>
</e-axes>
</ejs-lineargauge>`
})
export class AppComponent implements OnInit {
public tooltip?:Object;
ngOnInit(): void {
this.tooltip = {
enable: true,
position: "Center"
};
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Pointer Drag
To drag either marker or bar pointer to the desired axis value, set the enableDrag
property as true in the pointer
.
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, OnInit } from '@angular/core';
@Component({
imports: [
LinearGaugeModule
],
providers: [ GaugeTooltipService ],
standalone: true,
selector: 'app-container',
template: `<ejs-lineargauge id="gauge-container" style='display:block;' height='350'>
<e-axes>
<e-axis>
<e-pointers>
<e-pointer value=80 [enableDrag]=true></e-pointer>
</e-pointers>
</e-axis>
</e-axes>
</ejs-lineargauge>`
})
export class AppComponent implements OnInit {
ngOnInit(): void {
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));