Animation in Angular Linear gauge component

27 Apr 20245 minutes to read

All of the elements in the Linear Gauge, such as the axis lines, ticks, labels, ranges, pointers, and annotations, can be animated sequentially by using the animationDuration property. The animation for the Linear Gauge is enabled when the animationDuration property is set to an appropriate value in milliseconds, providing a smooth rendering effect for the component. If the animationDuration property is set to 0, which is the default value, the animation effect is disabled. If the animation is enabled, the component will behave in the following order.

  1. The axis line, ticks, labels, and ranges will all be animated at the same time.
  2. If available, pointers will be animated in the same way as pointer animation.
  3. If available, annotations will be animated.

The animation of the Linear Gauge is demonstrated in the following example.

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='defaultContainer' background='transparent' style='display:block;'
        orientation='Horizontal' [annotations]='annotation' [axes]='axes' animationDuration="3000">
    </ejs-lineargauge>`,
})

export class AppComponent {
  public axes?: Object[];
  public annotation?: Object;
  ngOnInit(): void {
    this.axes = [
      {
        pointers: [
          {
            value: 10,
            height: 15,
            width: 15,
            placement: 'Near',
            offset: -40,
            markerType: 'Triangle',
          },
        ],
        ranges: [
          {
            start: 0,
            end: 50,
            startWidth: 10,
            endWidth: 10,
            color: '#F45656',
            offset: 35,
          },
        ],
        majorTicks: {
          interval: 10,
          height: 20,
          color: '#9E9E9E',
        },
        minorTicks: {
          interval: 2,
          height: 10,
          color: '#9E9E9E',
        },
        labelStyle: {
          offset: 48,
          font: { fontFamily: 'inherit' },
        },
      },
    ];
    this.annotation = [
      {
        content:
          '<div style="width: 70px;margin-left:-3%;margin-top: 42%;font-size: 16px;">10 MPH</div>',
        axisIndex: 0,
        axisValue: 10,
        x: 10,
        y: -70,
        zIndex: '1',
      },
    ];
  }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Only the pointer of the Linear Gauge can be animated individually, not the axis lines, ticks, labels, ranges, and annotations. You can refer this link to enable only pointer animation.