The jqxBarGauge component from jqWidgets is a powerful tool for visualizing values in a circular bar format. This guide provides step-by-step instructions and examples for integrating and using jqxBarGauge in Angular applications.
Install the jqWidgets library in your Angular project using npm:
npm install jqwidgets-ng --save
To ensure proper styling of the jqxBarGauge component, include the jqWidgets base CSS file in your project. Add the following line to the angular.json
file under the styles
array:
"styles": [
"src/styles.css",
"node_modules/jqwidgets-ng/jqwidgets/styles/jqx.base.css"
]
Angular supports standalone components, a modern and streamlined approach for building Angular applications. This example demonstrates using jqxBarGauge in a standalone component.
Below is an example of a standalone Angular component using jqxBarGauge:
// main.ts
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
// app.component.ts
import { Component } from '@angular/core';
import { jqxBarGaugeModule } from 'jqwidgets-ng/jqxbargauge';
@Component({
selector: 'app-root',
standalone: true,
imports: [jqxBarGaugeModule],
template: `
<jqxBarGauge
[max]="100"
[values]="values"
[colorScheme]="'scheme01'"
(onDrawEnd)="handleDrawEnd($event)"
></jqxBarGauge>
`,
styles: [
`
jqxBarGauge {
margin: auto;
display: block;
}
`,
],
})
export class AppComponent {
values = [30, 70, 90];
handleDrawEnd(event: any): void {
console.log('DrawEnd event triggered:', event);
}
}
jqxBarGauge offers a wide range of features to enhance your visualizations:
[colorScheme]
property.[labels]
and [formatFunction]
.[values]
property to your application data model.[tooltip]
property.jqxBarGauge emits various events to help you create interactive applications. For example:
<jqxBarGauge
[values]="values"
(onDrawEnd)="handleDrawEnd($event)"
(onValueChanged)="handleValueChanged($event)"
></jqxBarGauge>
In the component class:
handleDrawEnd(event: any): void {
console.log('DrawEnd event:', event);
}
handleValueChanged(event: any): void {
console.log('ValueChanged event:', event);
}
With this guide, you can seamlessly integrate jqxBarGauge into your Angular applications. Its customizable features and event-handling capabilities make it a great choice for data visualization. For more details and advanced usage, visit the jqWidgets documentation.