layout | title | description | platform | control | documentation | domainurl |
---|---|---|---|---|---|---|
post |
Getting started with Angular Linear gauge component | Syncfusion |
Checkout and learn about Getting started with Angular Linear gauge component of Syncfusion Essential JS 2 and more details. |
ej2-angular |
Getting started |
ug |
This section explains the steps required to create a simple Linear Gauge and demonstrate the basic usage of the Linear Gauge component.
{% youtube "https://www.youtube.com/watch?v=KHAuX1TQisU" %}
Below is the list of minimum dependencies required to use the Linear Gauge component.
|-- @syncfusion/ej2-angular-lineargauge
|-- @syncfusion/ej2-angular-base
|-- @syncfusion/ej2-angular-lineargauge
|-- @syncfusion/ej2-lineargauge
|-- @syncfusion/ej2-base
|-- @syncfusion/ej2-svg-base
Angular CLI
can be used to setup the Angular applications. To install Angular CLI use the following command.
npm install -g @angular/cli
Start a new Angular application using below Angular CLI command.
ng new my-app
cd my-app
Syncfusion® packages are distributed in npm as @syncfusion
scoped packages. You can get all the Angular Syncfusion® package from npm link.
Currently, Syncfusion® provides two types of package structures for Angular components,
- Ivy library distribution package format
- Angular compatibility compiler(Angular’s legacy compilation and rendering pipeline) package.
Syncfusion® Angular packages(>=20.2.36
) has been moved to the Ivy distribution to support the Angular Ivy rendering engine and the package are compatible with Angular version 12 and above. To download the package use the below command.
Add @syncfusion/ej2-angular-lineargauge
package to the application.
npm install @syncfusion/ej2-angular-lineargauge --save
For Angular version below 12, you can use the legacy (ngcc) package of the Syncfusion® Angular components. To download the ngcc
package use the below.
Add @syncfusion/ej2-angular-lineargauge@ngcc
package to the application.
npm install @syncfusion/ej2-angular-lineargauge@ngcc --save
To mention the ngcc package in the package.json
file, add the suffix -ngcc
with the package version as below.
@syncfusion/ej2-angular-lineargauge:"20.2.38-ngcc"
Note: If the ngcc tag is not specified while installing the package, the Ivy Library Package will be installed and this package will throw a warning.
Modify the template in app.component.ts file to render the Linear Gauge component.
[src/app/app.component.ts]
.
import { LinearGaugeModule } from '@syncfusion/ej2-angular-lineargauge'
import { Component } from '@angular/core';
@Component({
imports: [
LinearGaugeModule
],
standalone: true,
selector: 'app-container',
// specifies the template string for the linear gauge component
template: `<ejs-lineargauge id="gauge-container"></ejs-lineargauge>`
})
export class AppComponent {
}
Now use the <code>app-container</code>
in the index.html instead of default one.
```
<app-container></app-container>
```
-
Now run the application in the browser using the below command.
npm start
The below example shows a basic Linear Gauge.
{% tabs %} {% highlight ts tabtitle="app.component.ts" %} {% include code-snippet/linear-gauge/getting-started-cs1/src/app.component.ts %} {% endhighlight %}
{% highlight ts tabtitle="main.ts" %} {% include code-snippet/linear-gauge/getting-started-cs1/src/main.ts %} {% endhighlight %} {% endtabs %}
{% previewsample "page.domainurl/samples/linear-gauge/getting-started-cs1" %}
LinearGauge component is segregated into the individual feature-wise modules. In order to use a particular feature, inject its feature module using the providers: {}
. Please find the feature module name and description as follows.
AnnotationsService
- Inject this provider to use Annotation feature.GaugeTooltipService
- Inject this provider to use Tooltip feature.
These modules should be injected in the providers section of the app.component.ts file as follows,
import { LinearGaugeModule } from '@syncfusion/ej2-angular-lineargauge'
import { Component } from '@angular/core';
import { AnnotationsService, GaugeTooltipService} from '@syncfusion/ej2-angular-lineargauge';
@Component({
imports: [
LinearGaugeModule,
],
standalone: true,
providers: [ AnnotationsService, GaugeTooltipService ]
})
The title can be added to the Linear Gauge component using the title
property in the Linear Gauge.
{% tabs %} {% highlight ts tabtitle="app.component.ts" %} {% include code-snippet/linear-gauge/getting-started-cs2/src/app.component.ts %} {% endhighlight %}
{% highlight ts tabtitle="main.ts" %} {% include code-snippet/linear-gauge/getting-started-cs2/src/main.ts %} {% endhighlight %} {% endtabs %}
{% previewsample "page.domainurl/samples/linear-gauge/getting-started-cs2" %}
The range of the axis can be set using the minimum
and maximum
properties in the Linear Gauge.
{% tabs %} {% highlight ts tabtitle="app.component.ts" %} {% include code-snippet/linear-gauge/getting-started-cs3/src/app.component.ts %} {% endhighlight %}
{% highlight ts tabtitle="main.ts" %} {% include code-snippet/linear-gauge/getting-started-cs3/src/main.ts %} {% endhighlight %} {% endtabs %}
{% previewsample "page.domainurl/samples/linear-gauge/getting-started-cs3" %}
To denote the axis labels with temperature units, add the °C as suffix to each label. This can be achieved by setting the {value}°C to the format
property in the labelStyle
object of the axis. Here, {value} acts as a placeholder for each axis label.
To change the pointer value from the default value of the gauge, set the value
property in pointers
object of the axis.
{% tabs %} {% highlight ts tabtitle="app.component.ts" %} {% include code-snippet/linear-gauge/getting-started-cs4/src/app.component.ts %} {% endhighlight %}
{% highlight ts tabtitle="main.ts" %} {% include code-snippet/linear-gauge/getting-started-cs4/src/main.ts %} {% endhighlight %} {% endtabs %}
{% previewsample "page.domainurl/samples/linear-gauge/getting-started-cs4" %}
The pointer value is changed in the below sample using the value
property in pointers
object of the axis.
{% tabs %} {% highlight ts tabtitle="app.component.ts" %} {% include code-snippet/linear-gauge/getting-started-cs5/src/app.component.ts %} {% endhighlight %}
{% highlight ts tabtitle="main.ts" %} {% include code-snippet/linear-gauge/getting-started-cs5/src/main.ts %} {% endhighlight %} {% endtabs %}
{% previewsample "page.domainurl/samples/linear-gauge/getting-started-cs5" %}