Movatterモバイル変換


[0]ホーム

URL:


PDF
Edit
Suggest a Feature

    Getting started in EJ2 TypeScript Linear gauge control

    7 May 202514 minutes to read

    This section briefly explains how to createLinear Gauge component and configure its available functionalities in TypeScript using the Essential® JS 2quickstart seed repository.

    This application is integrated with thewebpack.config.js configuration and uses the latest version of thewebpack-cli. It requires nodev14.15.0 or higher. For more information about webpack and its features, refer to thewebpack documentation.

    Dependencies

    Following is the list of minimum dependencies required to use the Linear Gauge.

    |--@syncfusion/ej2-lineargauge|--@syncfusion/ej2-base|--@syncfusion/ej2-pdf-export|--@syncfusion/ej2-svg-base

    Set up development environment

    Open the command prompt from the required directory, and run the following command to clone the Syncfusion® JavaScript (Essential® JS 2) quickstart project fromGitHub.

    git clone https://github.com/SyncfusionExamples/ej2-quickstart-webpack- ej2-quickstart

    After cloning the application in theej2-quickstart folder, run the following command line to navigate to theej2-quickstart folder.

    cd ej2-quickstart

    Add Syncfusion® JavaScript packages

    Syncfusion® JavaScript (Essential® JS 2) packages are available on thenpmjs.com public registry. You can install all Syncfusion® JavaScript (Essential® JS 2) controls in a single@syncfusion/ej2 package or individual packages for each control.

    The quickstart application is preconfigured with the dependent@syncfusion/ej2 package in the~/package.json file. Use the following command to install the dependent npm packages from the command prompt.

    npm install

    Adding Linear Gauge component to the Project

    The Essential® JS2 Linear Gauge component can be added to the application. To get started, add the Linear Gauge component to theapp.ts andindex.html files using the following code.

    Add an HTML div element to act as the Linear Gauge element in theindex.html file using the following code.

    <!DOCTYPE html><htmllang="en"><head><title>EJ2 Linear gauge</title><metacharset="utf-8"/><metaname="viewport"content="width=device-width, initial-scale=1.0"/><metaname="description"content="Typescript UI Controls"/><metaname="author"content="Syncfusion"/></head><body><!-- container which is going to render the linear gauge --><divid='container'></div></body></html>

    Import the LinearGauge component in theapp.ts file to initialize the Linear Gauge and append the Linear Gauge instance to the#container.

    import{LinearGauge}from'@syncfusion/ej2-lineargauge';// initialize linear gauge componentletgauge:LinearGauge=newLinearGauge();// render initialized linear gaugegauge.appendTo('#container');

    Run the application

    The quickstart project is configured to compile and run the application in the browser. Use the following command to run the application.

    npm start

    The below example shows a basic Linear Gauge component.

    import{LinearGauge}from'@syncfusion/ej2-lineargauge';letgauge:LinearGauge=newLinearGauge();gauge.appendTo('#element');
    <!DOCTYPE html><htmllang="en"><head><title>EJ2 Animation</title><metacharset="utf-8"/><metaname="viewport"content="width=device-width, initial-scale=1.0"/><metaname="description"content="Typescript UI Controls"/><metaname="author"content="Syncfusion"/><linkhref="index.css"rel="stylesheet"/><linkhref="https://cdn.syncfusion.com/ej2/31.2.12/ej2-popups/styles/material.css"rel="stylesheet"/><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script><scriptsrc="systemjs.config.js"></script><scriptsrc="https://cdn.syncfusion.com/ej2/syncfusion-helper.js"type="text/javascript"></script></head><body><divid='loader'>Loading....</div><divid='container'><divid='element'></div></div></body></html>

    Module Injection

    Linear Gauge component is segregated into individual feature-wise modules. In order to use a particular feature, inject its corresponding feature module usingLinearGauge.Inject() method. Please find the feature module name and description as follows.

    • Annotation - Inject this module to use the annotation features.
    • GaugeTooltip - Inject this module to use the tooltip features.

    Now import the above mentioned modules from the Linear Gauge package and inject it into the LinearGauge component usingLinearGauge.Inject method.

    import{GaugeTooltip,Annotations}from'@syncfusion/ej2-lineargauge';LinearGauge.Inject(Annotations,GaugeTooltip);

    Adding the Linear Gauge Title

    The title can be added to the Linear Gauge component using thetitle property in the Linear Gauge.

    import{LinearGauge}from'@syncfusion/ej2-lineargauge';letgauge:LinearGauge=newLinearGauge({// Title for linear gaugetitle:'linear gauge'},'#element');
    <!DOCTYPE html><htmllang="en"><head><title>EJ2 Animation</title><metacharset="utf-8"/><metaname="viewport"content="width=device-width, initial-scale=1.0"/><metaname="description"content="Typescript UI Controls"/><metaname="author"content="Syncfusion"/><linkhref="index.css"rel="stylesheet"/><linkhref="https://cdn.syncfusion.com/ej2/31.2.12/ej2-popups/styles/material.css"rel="stylesheet"/><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script><scriptsrc="systemjs.config.js"></script><scriptsrc="https://cdn.syncfusion.com/ej2/syncfusion-helper.js"type="text/javascript"></script></head><body><divid='loader'>Loading....</div><divid='container'><divid='element'></div></div></body></html>

    Axis Range

    The range of the axis can be set using theminimum andmaximum properties in the Linear Gauge.

    import{LinearGauge}from'@syncfusion/ej2-lineargauge';letgauge:LinearGauge=newLinearGauge({axes:[{minimum:0,maximum:200}]},'#element');
    <!DOCTYPE html><htmllang="en"><head><title>EJ2 Animation</title><metacharset="utf-8"/><metaname="viewport"content="width=device-width, initial-scale=1.0"/><metaname="description"content="Typescript UI Controls"/><metaname="author"content="Syncfusion"/><linkhref="index.css"rel="stylesheet"/><linkhref="https://cdn.syncfusion.com/ej2/31.2.12/ej2-popups/styles/material.css"rel="stylesheet"/><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script><scriptsrc="systemjs.config.js"></script><scriptsrc="https://cdn.syncfusion.com/ej2/syncfusion-helper.js"type="text/javascript"></script></head><body><divid='loader'>Loading....</div><divid='container'><divid='element'></div></div></body></html>

    To denote the axis values with temperature units, add the °C as suffix to each label. This can be achieved by setting the{value}°C to theformat property in thelabelStyle 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 thevalue property inpointers object of the axis.

    import{LinearGauge}from'@syncfusion/ej2-lineargauge';letgauge:LinearGauge=newLinearGauge({axes:[{minimum:0,maximum:200,pointers:[{value:140}],labelStyle:{format:'{value}°C'},ranges:[{start:0,end:80,startWidth:15,endWidth:15},{start:80,end:120,startWidth:15,endWidth:15},{start:120,end:140,startWidth:15,endWidth:15},{start:140,end:200,startWidth:15,endWidth:15}]}]},'#element');
    <!DOCTYPE html><htmllang="en"><head><title>EJ2 Animation</title><metacharset="utf-8"/><metaname="viewport"content="width=device-width, initial-scale=1.0"/><metaname="description"content="Typescript UI Controls"/><metaname="author"content="Syncfusion"/><linkhref="index.css"rel="stylesheet"/><linkhref="https://cdn.syncfusion.com/ej2/31.2.12/ej2-popups/styles/material.css"rel="stylesheet"/><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script><scriptsrc="systemjs.config.js"></script><scriptsrc="https://cdn.syncfusion.com/ej2/syncfusion-helper.js"type="text/javascript"></script></head><body><divid='loader'>Loading....</div><divid='container'><divid='element'></div></div></body></html>

    Setting the value of the pointer

    The pointer value is changed in the below sample using thevalue property inpointers object of the axis.

    import{LinearGauge}from'@syncfusion/ej2-lineargauge';letgauge:LinearGauge=newLinearGauge({axes:[{pointers:[{value:40,color:'green'}]}]},'#element');
    <!DOCTYPE html><htmllang="en"><head><title>EJ2 Animation</title><metacharset="utf-8"/><metaname="viewport"content="width=device-width, initial-scale=1.0"/><metaname="description"content="Typescript UI Controls"/><metaname="author"content="Syncfusion"/><linkhref="index.css"rel="stylesheet"/><linkhref="https://cdn.syncfusion.com/ej2/31.2.12/ej2-popups/styles/material.css"rel="stylesheet"/><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script><scriptsrc="systemjs.config.js"></script><scriptsrc="https://cdn.syncfusion.com/ej2/syncfusion-helper.js"type="text/javascript"></script></head><body><divid='loader'>Loading....</div><divid='container'><divid='element'></div></div></body></html>

    Help us improve this page

    Please provide additional information

    Please provide additional information

    Please provide additional information

    Please provide additional information

    Please provide additional information
    Please provide additional information
    ×

    [8]ページ先頭

    ©2009-2025 Movatter.jp