Search results

Ranges in Angular Linear Gauge component

28 Jul 2021 / 5 minutes to read

Range is the set of values in the axis. The range can be defined using the start and end properties in the e-range. Any number of ranges can be added to the Linear Gauge using the e-ranges.

Source
Preview
app.component.ts
app.module.ts
main.ts
Copied to clipboard
import { Component } from '@angular/core';

@Component({
    selector: 'app-container',
    template: `
    <ejs-lineargauge id="gauge-container">
        <e-axes>
         <e-axis>
           <e-ranges>
             <e-range start=50 end=80></e-range>
           </e-ranges>
         </e-axis>
      </e-axes>
    </ejs-lineargauge>`
})
export class AppComponent {
    ngOnInit(): void {
    }
}
Copied to clipboard
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 { }
Copied to clipboard
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

Customizing the range

Ranges can be customized using the following properties in e-range.

  • startWidth - To set the thickness of the range at the start axis value.
  • endWidth - To set the thickness of the range at the end axis value.
  • color - To set the color of the range.
  • position - To place the range. By default, the range is placed outside of the axis. To change the position, this property can be set as ”Inside”, ”Outside”, ”Cross”, or ”Auto“.
  • Offset - To place the range with the specified distance from the axis.
  • border - To set the color and width for the border of the range.
Source
Preview
app.component.ts
app.module.ts
main.ts
Copied to clipboard
import { Component } from '@angular/core';

@Component({
selector: 'app-container',
template: `
<ejs-lineargauge id="gauge-container">
    <e-axes>
     <e-axis>
       <e-ranges>
         <e-range start=50 end=80 startWidth=15 endWidth=15 color="Orange"></e-range>
       </e-ranges>
     </e-axis>
  </e-axes>
</ejs-lineargauge>`
})
export class AppComponent {
ngOnInit(): void {
}
}
Copied to clipboard
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 { }
Copied to clipboard
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

Setting the range color for the labels

To set the color of the labels like the range color, set the useRangeColor property as ”true” in the labelStyle.

Source
Preview
app.component.ts
app.module.ts
main.ts
Copied to clipboard
import { Component } from '@angular/core';

@Component({
selector: 'app-container',
template: `
<ejs-lineargauge id="gauge-container">
    <e-axes>
     <e-axis [labelStyle]='labelStyle'>
       <e-ranges>
         <e-range start=50 end=80 startWidth=15 endWidth=15 color="red"></e-range>
       </e-ranges>
     </e-axis>
  </e-axes>
</ejs-lineargauge>`
})
export class AppComponent {
  public labelStyle: Object;
  ngOnInit(): void {
this.labelStyle = {
  useRangeColor: true
};
  }
}
Copied to clipboard
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 { }
Copied to clipboard
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

Multiple ranges

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

Source
Preview
app.component.ts
app.module.ts
main.ts
Copied to clipboard
import { Component } from '@angular/core';

@Component({
selector: 'app-container',
template: `
<ejs-lineargauge id="gauge-container">
    <e-axes>
     <e-axis>
       <e-ranges>
         <e-range start=0 end=30 startWidth=10 endWidth=10 color='#41f47f'></e-range>
         <e-range start=30 end=50 startWidth=10 endWidth=10 color='#f49441'></e-range>
         <e-range start=50 end=100 startWidth=10 endWidth=10  color='#cd41f4'></e-range>
       </e-ranges>
     </e-axis>
  </e-axes>
</ejs-lineargauge>`
})
export class AppComponent {
  ngOnInit(): void {
}
}
Copied to clipboard
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 { }
Copied to clipboard
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

Gradient Color

Gradient support allows the addition of multiple colors in the range 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. The linear gradient can be rendered for the range in the Linear Gauge by using the below example.

Source
Preview
app.component.ts
app.module.ts
main.ts
Copied to clipboard
import { Component, OnInit } from '@angular/core';

@Component({
selector: 'app-container',
template: `
 <ejs-lineargauge id="gauge-container" [container]='container' orientation='horizontal' [axes]='axes'>
</ejs-lineargauge>`
})
export class AppComponent {
  public container: Object;
  public axes: Object[];
ngOnInit(): void {
  // Initialize objects
  this.container = { width: 30, offset: 30 }
  this.axes = [{
    minimum: 0,
    maximum: 100,
    line: {
      width: 0
    },
    majorTicks: {
      interval: 25,
      height: 0
    },
    minorTicks: {
      height: 0
    },
    labelStyle: {
      font: {
      color: '#424242',
      }, offset: 55
    },
    pointers: [{
      value: 80, height: 25,
      width: 35, placement: 'Near',
      offset: -44, markerType: 'Triangle',
      color: '#f54ea2'
    }],
    ranges: [{
      start: 0, end: 80,
      startWidth: 30, endWidth: 30,
      offset: 30,
      linearGradient: {
        startValue: '0%',
        endValue: '100%',
        colorStop: [
          { color: '#fef3f9', offset: '0%', opacity: 1 },
          { color: '#f54ea2', offset: '100%', opacity: 1 }]
      }
    }]
  }];
}
}
Copied to clipboard
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 { }
Copied to clipboard
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

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. The radial gradient can be rendered for the range in the Linear Gauge by using the below example.

Source
Preview
app.component.ts
app.module.ts
main.ts
Copied to clipboard
import { Component, OnInit } from '@angular/core';

@Component({
selector: 'app-container',
template: `
 <ejs-lineargauge id="gauge-container" [container]='container' orientation='Horizontal' [axes]='axes'>
</ejs-lineargauge>`
})
export class AppComponent {
  public container: Object;
  public axes: Object[];
ngOnInit(): void {
  // Initialize objects
  this.container = { width: 30, offset: 30 }
  this.axes = [{
    minimum: 0,
    maximum: 100,
    line: {
      width: 0
    },
    majorTicks: {
      interval: 25,
      height: 0
    },
    minorTicks: {
      height: 0
    },
    labelStyle: {
      font: {
      color: '#424242',
      }, offset: 55
    },
    pointers: [{
      value: 80, height: 25,
      width: 35, placement: 'Near',
      offset: -44, markerType: 'Triangle',
      color: '#f54ea2'
    }],
    ranges: [{
      start: 0, end: 80,
      startWidth: 30, endWidth: 30,
      offset: 30,
      radialGradient: {
        radius: '65%',
        outerPosition: { x: '50%', y: '70%' },
        innerPosition: { x: '60%', y: '60%' },
        colorStop: [
        { color: '#fff5f5', offset: '5%', opacity: 0.9 },
        { color: '#f54ea2', offset: '100%', opacity: 0.9 }]
        }
    }]
  }];
}
}
Copied to clipboard
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 { }
Copied to clipboard
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

Note: If we set both gradients for the range, 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 range of the Linear Gauge.