DevExtreme v26.1 is now available.

Explore our newest features/capabilities and share your thoughts with us.

Your search did not match any results.

Angular Gauges - Subvalue Indicators Runtime Customization

This demo shows how to use the API of the LinearGauge to change its value and subvalue indicators at runtime. To get and set values of the indicators, the value and subvalues methods are utilized.

Backend API
<div id="gauge-demo"> <dx-linear-gauge id="gauge" [value]="currentValue.primary" [subvalues]="currentValue.secondary" > <dxo-linear-gauge-scale [startValue]="0" [endValue]="10" [tickInterval]="2"> <dxo-linear-gauge-label [customizeText]="customizeText" ></dxo-linear-gauge-label> </dxo-linear-gauge-scale> <dxo-linear-gauge-tooltip [enabled]="true" [customizeTooltip]="customizeTooltip" ></dxo-linear-gauge-tooltip> <dxo-linear-gauge-export [enabled]="true"></dxo-linear-gauge-export> <dxo-linear-gauge-title text="Power of Air Conditioners in Store Departments (kW)" > <dxo-linear-gauge-font [size]="28"></dxo-linear-gauge-font> </dxo-linear-gauge-title> </dx-linear-gauge> <dx-select-box #select [dataSource]="powerInfo" [inputAttr]="{ 'aria-label': 'Department' }" displayExpr="name" [(value)]="currentValue" [width]="200" > </dx-select-box> </div>
import { bootstrapApplication } from '@angular/platform-browser'; import { Component, enableProdMode, provideZoneChangeDetection } from '@angular/core'; import { DxSelectBoxModule } from 'devextreme-angular'; import { DxLinearGaugeModule, DxLinearGaugeTypes } from 'devextreme-angular/ui/linear-gauge'; import { Service, PowerInfo } from './app.service'; if (!/localhost/.test(document.location.host)) { enableProdMode(); } @Component({ selector: 'demo-app', templateUrl: './app.component.html', styleUrls: ['./app.component.css'], providers: [Service], imports: [ DxLinearGaugeModule, DxSelectBoxModule, ], }) export class AppComponent { powerInfo: PowerInfo[]; currentValue: PowerInfo; constructor(service: Service) { this.powerInfo = service.getPowerInfo(); this.currentValue = this.powerInfo[0]; } customizeText: DxLinearGaugeTypes.ScaleLabel['customizeText'] = ({ valueText }) => `${valueText} kW`; customizeTooltip({ index, valueText }) { let result = `${valueText} kW`; result = (index >= 0) ? `Secondary ${index + 1}: ${result}` : `Primary: ${result}`; return { text: result, }; } } bootstrapApplication(AppComponent, { providers: [ provideZoneChangeDetection({ eventCoalescing: true, runCoalescing: true }), ], });
::ng-deep #gauge-demo { height: 440px; width: 100%; } ::ng-deep #gauge { height: 400px; }
import { Injectable } from '@angular/core'; export class PowerInfo { name: string; primary: number; secondary: number[]; } const powerInfo: PowerInfo[] = [{ name: 'Meat', primary: 8, secondary: [7, 3], }, { name: 'Fish', primary: 7, secondary: [7, 5, 1], }, { name: 'Grocery', primary: 5, secondary: [1, 3], }, { name: 'Greengrocery', primary: 3, secondary: [1], }, { name: 'Stationery', primary: 2, secondary: [], }]; @Injectable() export class Service { getPowerInfo(): PowerInfo[] { return powerInfo; } }
<!DOCTYPE html> <html lang="en"> <head> <title>DevExtreme Demo</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/26.1.5/css/dx.light.css" /> </head> <body class="dx-viewport"> <div class="demo-container"> <demo-app>Loading...</demo-app> </div> <script src="https://cdn.jsdelivr.net/npm/zone.js@0.16.2/bundles/zone.umd.js"></script> <script src="./bundle.js" type="module"></script> </body> </html>