Pointers in Angular Linear gauge component

26 Dec 202324 minutes to read

Pointers are used to indicate values on an axis. The value of the pointer can be modified using the value property in e-pointer.

import { Component } from '@angular/core';

@Component({
    selector: 'app-container',
    template: `
    <ejs-lineargauge id="gauge-container">
        <e-axes>
         <e-axis>
           <e-pointers>
             <e-pointer value=40></e-pointer>
           </e-pointers>
         </e-axis>
      </e-axes>
    </ejs-lineargauge>`
})
export class AppComponent {
    ngOnInit(): void {
    }
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { LinearGaugeModule } from '@syncfusion/ej2-angular-lineargauge';
import { GaugeTooltipService, GradientService } from '@syncfusion/ej2-angular-lineargauge';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule, LinearGaugeModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
    providers: [ GaugeTooltipService, GradientService ]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

import 'zone.js';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

Types of pointer

The Linear Gauge supports the following types of pointers.

  • Bar
  • Marker

The type of pointer can be modified by using the type property in e-pointer.

Marker pointer

A marker pointer is a shape that can be used to mark the pointer value in the Linear Gauge.

Types of marker shapes

By default, the marker shape for the pointer is InvertedTriangle. To change the shape of the pointer, use the markerType property in e-pointer. The following marker types are available in Linear Gauge.

  • Circle
  • Rectangle
  • Triangle
  • InvertedTriangle
  • Diamond
  • Image
  • Text
import { Component } from '@angular/core';

@Component({
    selector: 'app-container',
    template: `
    <ejs-lineargauge id="gauge-container">
        <e-axes>
         <e-axis>
           <e-pointers>
             <e-pointer value=80 markerType='Circle'></e-pointer>
           </e-pointers>
         </e-axis>
      </e-axes>
    </ejs-lineargauge>`
})
export class AppComponent {
    ngOnInit(): void {
    }
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { LinearGaugeModule } from '@syncfusion/ej2-angular-lineargauge';
import { GaugeTooltipService, GradientService } from '@syncfusion/ej2-angular-lineargauge';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule, LinearGaugeModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
    providers: [ GaugeTooltipService, GradientService ]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

import 'zone.js';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

Image can be rendered instead of rendering a shape as a pointer. It can be achieved by setting the markerType property to Image and setting the source URL of image to imageUrl property in e-pointer.

import { Component } from '@angular/core';

@Component({
  selector: 'app-container',
  template: `
    <ejs-lineargauge id="gauge-container" orientation="Horizontal">
        <e-axes>
         <e-axis [majorTicks]='major' [minorTicks]='minor' [labelStyle]='label'>
           <e-pointers>
             <e-pointer value=60 markerType="Image" width="40" height="40" imageUrl="https://ej2.syncfusion.com/angular/demos/assets/linear-gauge/images/step-count.png" offset="-27"></e-pointer>
           </e-pointers>
         </e-axis>
      </e-axes>
    </ejs-lineargauge>`,
})
export class AppComponent {
  public major?: Object;
  public minor?: Object;
  public label?: Object;
  ngOnInit(): void {
    this.label = {
      position: 'Outside',
    };
    this.major = {
      interval: 20,
      position: 'Outside',
    };
    this.minor = {
      position: 'Outside',
    };
  }
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { LinearGaugeModule } from '@syncfusion/ej2-angular-lineargauge';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule, LinearGaugeModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

import 'zone.js';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

Text can be added instead of rendering a shape as a pointer. It can be achieved by setting the markerType property to Text, and the text content can be set using the text property in e-pointer.

The following properties in the textStyle property can be used to set the text style for the text pointer.

  • fontFamily - It is used to set the font family for the text pointer.
  • fontStyle - It is used to set the font style for the text pointer.
  • fontWeight - It is used to set the font weight for the text pointer.
  • size - It is used to set the font size for the text pointer.
import { Component } from '@angular/core';

@Component({
  selector: 'app-container',
  template: `
    <ejs-lineargauge id="gauge-container" orientation="Horizontal">
        <e-axes>
         <e-axis [majorTicks]='majorTicks' [minorTicks]='minorTicks' [labelStyle]='labelStyle' [line]="lineStyle">
           <e-pointers>
             <e-pointer value="13" markerType="Text" text="Low" color="black" offset="-35" [textStyle]="textStyle"></e-pointer>
             <e-pointer value="48" markerType="Text" text="Moderate" color="black" offset="-35" [textStyle]="textStyle"></e-pointer>
             <e-pointer value="83" markerType="Text" text="High" color="black" offset="-35" [textStyle]="textStyle"></e-pointer>
           </e-pointers>
           <e-ranges>
             <e-range start=0 end=30 color='#6FC78A' startWidth=50 endWidth=50 position='Outside'></e-range>
             <e-range start=30 end=65 color='#ECC85B' startWidth=50 endWidth=50 position='Outside'></e-range>
             <e-range start=65 end=100 color='#FB7D55' startWidth=50 endWidth=50 position='Outside'></e-range>
           </e-ranges>
         </e-axis>
      </e-axes>
    </ejs-lineargauge>`,
})
export class AppComponent {
  public majorTicks?: Object;
  public minorTicks?: Object;
  public labelStyle?: Object;
  public textStyle?: Object;
  public lineStyle?: Object;
  ngOnInit(): void {
    this.lineStyle = {
      width: 0,
    };
    this.majorTicks = {
      interval: 20,
      height: 7,
      width: 1,
      position: 'Outside',
    };
    this.minorTicks = {
      interval: 10,
      height: 3,
      position: 'Outside',
    };
    this.textStyle = {
      size: '18px',
      fontWeight: 'bold',
    };
    this.labelStyle = {
      position: 'Outside',
      font: { fontFamily: 'inherit' },
    };
  }
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { LinearGaugeModule } from '@syncfusion/ej2-angular-lineargauge';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule, LinearGaugeModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

import 'zone.js';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

Marker Pointer Customization

The marker pointer can be customized using the following properties.

  • height - To set the height of the pointer.
  • position - The position of the pointer can be changed by setting the value as Inside, Outside, Cross, or Auto.
  • width - To set the width of the pointer.
  • color - To set the color of the pointer.
  • placement - To place the pointer in the specified position. By default, the pointer is placed Far from the axis. To change the placement, set the placement property as Near, Center, or None.
  • offset - To place the pointer with specified distance from the axis.
  • opacity - To set the opacity of the pointer.
  • animationDuration - To specify the duration of the animation in pointer.
  • border - To set the color and width for the border of the pointer.
import { Component } from '@angular/core';

@Component({
    selector: 'app-container',
    template: `
    <ejs-lineargauge id="gauge-container">
        <e-axes>
         <e-axis>
           <e-pointers>
             <e-pointer value=80 markerType='Circle' [height]='height' [width]='width' color='#cd41f4'></e-pointer>
           </e-pointers>
         </e-axis>
      </e-axes>
    </ejs-lineargauge>`
})
export class AppComponent {
  public height?: number;
  public width?: number;
  ngOnInit(): void {
    this.height = 15;
    this.width= 15;
  }
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { LinearGaugeModule } from '@syncfusion/ej2-angular-lineargauge';
import { GaugeTooltipService, GradientService } from '@syncfusion/ej2-angular-lineargauge';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule, LinearGaugeModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
    providers: [ GaugeTooltipService, GradientService ]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

import 'zone.js';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

Bar Pointer

The bar pointer is used to track the axis value. The bar pointer starts from the beginning of the gauge and ends at the pointer value. To enable bar pointer set the type property in e-pointer as Bar.

import { Component } from '@angular/core';

@Component({
    selector: 'app-container',
    template: `
    <ejs-lineargauge id="gauge-container">
        <e-axes>
         <e-axis>
           <e-pointers>
             <e-pointer value=80 type='Bar'></e-pointer>
           </e-pointers>
         </e-axis>
      </e-axes>
    </ejs-lineargauge>`
})
export class AppComponent {
    ngOnInit(): void {
    }
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { LinearGaugeModule } from '@syncfusion/ej2-angular-lineargauge';
import { GaugeTooltipService, GradientService } from '@syncfusion/ej2-angular-lineargauge';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule, LinearGaugeModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
    providers: [ GaugeTooltipService, GradientService ]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

import 'zone.js';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

Bar pointer customization

The bar pointer can be customized using following properties.

  • width - To set the thickness of the bar pointer.
  • color - To set the color of the bar pointer.
  • offset - To place the bar pointer with the specified distance from it’s default position.
  • opacity - To set the opacity of the bar pointer.
  • roundedCornerRadius - To set the corner radius for the bar pointer.
  • border - To set the color and width for the border of the pointer.
  • animationDuration - To set the duration of the animation in bar pointer.

The placement property is not applicable for the bar pointer.

import { Component } from '@angular/core';

@Component({
    selector: 'app-container',
    template: `
    <ejs-lineargauge id="gauge-container">
        <e-axes>
         <e-axis>
           <e-pointers>
             <e-pointer value=60 type='Bar' width=20 color='#f44141'></e-pointer>
           </e-pointers>
         </e-axis>
      </e-axes>
    </ejs-lineargauge>`
})
export class AppComponent {
    ngOnInit(): void {
    }
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { LinearGaugeModule } from '@syncfusion/ej2-angular-lineargauge';
import { GaugeTooltipService, GradientService } from '@syncfusion/ej2-angular-lineargauge';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule, LinearGaugeModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
    providers: [ GaugeTooltipService, GradientService ]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

import 'zone.js';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

Multiple pointers

Multiple pointers can be added to the Linear Gauge by adding multiple e-pointer in the e-pointers and customization for the pointers can be done with e-pointer.

import { Component } from '@angular/core';

@Component({
    selector: 'app-container',
    template: `
    <ejs-lineargauge id="gauge-container">
        <e-axes>
         <e-axis>
           <e-pointers>
             <e-pointer value=80></e-pointer>
             <e-pointer value=60 markerType='Circle'></e-pointer>
             <e-pointer value=30 markerType='Diamond'></e-pointer>
           </e-pointers>
         </e-axis>
      </e-axes>
    </ejs-lineargauge>`
})
export class AppComponent {
    ngOnInit(): void {
    }
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { LinearGaugeModule } from '@syncfusion/ej2-angular-lineargauge';
import { GaugeTooltipService, GradientService } from '@syncfusion/ej2-angular-lineargauge';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule, LinearGaugeModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
    providers: [ GaugeTooltipService, GradientService ]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

import 'zone.js';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

Pointer animation

Pointer is animated on loading the gauge. This can be handled by using the animationDuration property. The duration of the animation can be specified in milliseconds.

import { Component } from '@angular/core';

@Component({
    selector: 'app-container',
    template: `
    <ejs-lineargauge id="gauge-container">
        <e-axes>
         <e-axis>
           <e-pointers>
             <e-pointer value=60 animationDuration=1000></e-pointer>
           </e-pointers>
         </e-axis>
      </e-axes>
    </ejs-lineargauge>`
})
export class AppComponent {
    ngOnInit(): void {
    }
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { LinearGaugeModule } from '@syncfusion/ej2-angular-lineargauge';
import { GaugeTooltipService, GradientService } from '@syncfusion/ej2-angular-lineargauge';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule, LinearGaugeModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
    providers: [ GaugeTooltipService, GradientService ]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

import 'zone.js';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

Gradient Color

Gradient support allows the addition of multiple colors in the pointers of the Linear Gauge. The following gradient types are supported in the Linear Gauge.

  • Linear Gradient
  • Radial Gradient

Linear Gradient

Using linear gradient, colors will be applied in a linear progression. The start value of the linear gradient can be set using the startValue property. The end value of the linear gradient will be set using the endValue property. The color stop values such as color, opacity and offset are set using colorStop property.

import { Component, OnInit } from '@angular/core';

@Component({
    selector: 'app-container',
    template: `
    <ejs-lineargauge id="gauge-container" [container]='container' orientation='horizontal'>
      <e-axes>
        <e-axis minimum=0 maximum=100 [line]='line' [majorTicks]='majorTicks' [minorTicks]='minorTicks' [labelStyle]='labelStyle' [pointers]='pointers' [ranges]='ranges'>
        </e-axis>
      </e-axes>
    </ejs-lineargauge>`
})
export class AppComponent {
  public container?: Object;
  public line?: Object;
  public majorTicks?: Object;
  public minorTicks?: Object;
  public labelStyle?: Object;
  public pointers?: Object[];
  public ranges?: Object[];
  ngOnInit(): void {
    this.container = { width: 30, offset: 30 }
    this.line= {
      width: 0
    };
    this.majorTicks= {
      interval: 25,
      height: 0
    };
    this.minorTicks= {
      height: 0
    },
    this.labelStyle= {
      font: {
        color: '#424242',
        size: '0px'
      }, offset: 55
    };
    this.pointers = [{
      value: 80, height: 25,
      width: 35, placement: 'Near',
      offset: -44, markerType: 'Triangle',
      linearGradient: {
        startValue: '0%',
        endValue: '100%',
        colorStop: [
          { color: '#fef3f9', offset: '0%', opacity: 1 },
          { color: '#f54ea2', offset: '100%', opacity: 1 }
        ]
      }
    }];
    this.ranges=[{
      start: 0, end: 80,
      startWidth: 30, endWidth: 30,
      color: '#f54ea2', offset: 30
    }]
  }
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { LinearGaugeModule } from '@syncfusion/ej2-angular-lineargauge';
import { GaugeTooltipService, GradientService } from '@syncfusion/ej2-angular-lineargauge';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule, LinearGaugeModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
    providers: [ GaugeTooltipService, GradientService ]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

import 'zone.js';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

Radial Gradient

Using radial gradient, colors will be applied in circular progression. The inner circle position of the radial gradient will be set using the innerPosition property. The outer circle position of the radial gradient can be set using the outerPosition property. The color stop values such as color, opacity, and offset are set using colorStop property.

import { Component, OnInit } from '@angular/core';

@Component({
    selector: 'app-container',
    template: `
    <ejs-lineargauge id="gauge-container" [container]='container' orientation='horizontal'>
      <e-axes>
        <e-axis minimum=0 maximum=100 [line]='line' [majorTicks]='majorTicks' [minorTicks]='minorTicks' [labelStyle]='labelStyle' [pointers]='pointers' [ranges]='ranges'>
        </e-axis>
      </e-axes>
    </ejs-lineargauge>`
})
export class AppComponent {
  public container?: Object;
  public line?: Object;
  public majorTicks?: Object;
  public minorTicks?: Object;
  public labelStyle?: Object;
  public pointers?: Object[];
  public ranges?: Object[];
  ngOnInit(): void {
    this.container = { width: 30, offset: 30 }
    this.line= {
      width: 0
    };
    this.majorTicks= {
      interval: 25,
      height: 0
    };
    this.minorTicks= {
      height: 0
    },
    this.labelStyle= {
      font: {
        color: '#424242',
        size: '0px'
      }, offset: 55
    };
    this.pointers = [{
      value: 80, height: 25,
      width: 35, placement: 'Near',
      offset: -44, markerType: 'Triangle',
      radialGradient: {
        radius: '60%',
        outerPosition: { x: '50%', y: '50%' },
        innerPosition: { x: '50%', y: '50%' },
        colorStop: [
          { color: '#fff5f5', offset: '0%', opacity: 0.9 },
          { color: '#f54ea2', offset: '100%', opacity: 0.8 }
        ]
      }
    }];
    this.ranges=[{
      start: 0, end: 80,
      startWidth: 30, endWidth: 30,
      color: '#f54ea2', offset: 30
    }]
  }
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { LinearGaugeModule } from '@syncfusion/ej2-angular-lineargauge';
import { GaugeTooltipService, GradientService } from '@syncfusion/ej2-angular-lineargauge';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule, LinearGaugeModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
    providers: [ GaugeTooltipService, GradientService ]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

import 'zone.js';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

If we set both gradients, only the linear gradient gets rendered. If we set the startValue and endValue property of the linearGradient as empty strings, then the radial gradient gets rendered in the pointer of the Linear Gauge.