Movatterモバイル変換


[0]ホーム

URL:


PDF
Edit
Suggest a Feature

    Getting started in EJ2 TypeScript Bullet chart control

    16 May 202514 minutes to read

    This section explains how to create a simple Bullet chart and configure its available functionalities in TypeScript using 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

    Below is the list of minimum dependencies required to use the Bullet Chart.

    |--@syncfusion/ej2-charts|--@syncfusion/ej2-base|--@syncfusion/ej2-data|--@syncfusion/ej2-pdf-export|--@syncfusion/ej2-file-utils|--@syncfusion/ej2-compression|--@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

    Add Bullet Chart to the Project

    Open the application in Visual Studio Code and add the Syncfusion JavaScript UI controls.

    Add the HTML div tag with itsid attribute aselement in your~/src/index.html file to initialize the Bullet chart.

    <!DOCTYPE html><htmllang="en"><head><title>EJ2 Bullet Chart</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 Bullet Chart--><divid='element'></div></body></html>

    Now import the Bullet Chart component into yourapp.ts to instantiate a bullet chart and append the bullet chart instance to the#element[src/app/app.ts]

    import{BulletChart}from'@syncfusion/ej2-charts';// initialize BulletChart componentletbulletChart:BulletChart=newBulletChart();// render initialized Bullet ChartbulletChart.appendTo('#element');

    Now use thenpm run start command to run the application in the browser.

    npm run start

    The below example shows a basic Chart.

    import{BulletChart}from'@syncfusion/ej2-charts';letbulletChart:BulletChart=newBulletChart();bulletChart.appendTo('#element');
    <!DOCTYPE html><htmllang="en"><head><title>Bullet Chart</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"/><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

    Bullet Chart component are segregated into individual feature-wise modules. In order to use a particular feature, you need to inject its feature module usingBulletChart.Inject() method. In the current application,we are going to use tooltip feature of the chart.

    • BulletTooltip - Inject this provider to use tooltip feature.

    Now import the above mentioned modules from Bullet Chart package and inject it into the Bullet Chart component usingBulletChart.Inject method.

    import{BulletChart,BulletTooltip}from'@syncfusion/ej2-charts';BulletChart.Inject(BulletTooltip);

    BulletChart With Data

    This section explains how to plot local data to the Bullet Chart.

    letdata:any[]=[{value:100,target:80},{value:200,target:180},{value:300,target:280},{value:400,target:380},{value:500,target:480},];

    Now assign the local data todataSource property.value andtarget values should be mapped withvalueField andtargetField respectively.

    import{BulletChart}from'@syncfusion/ej2-charts';letbulletChart:BulletChart=newBulletChart({dataSource:[{value:100,target:80},{value:200,target:180},{value:300,target:280},{value:400,target:380},{value:500,target:480}],valueField:'value',targetField:'target',height:'300',minimum:0,maximum:500,interval:50,});bulletChart.appendTo('#element');
    <!DOCTYPE html><htmllang="en"><head><title>Bullet Chart</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"/><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>

    Add Bullet Chart Title

    You can add a title usingtitle property to the Bullet Chart to provide quick information to the user about the data plotted in the Bullet Chart.

    import{BulletChart}from'@syncfusion/ej2-charts';letbulletChart:BulletChart=newBulletChart({dataSource:[{value:270,target:250},],valueField:'value',targetField:'target',title:'Revenue',minimum:0,maximum:300,interval:50,});bulletChart.appendTo('#element');
    <!DOCTYPE html><htmllang="en"><head><title>Bullet Chart</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"/><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>

    Ranges

    You can add a range usingranges property to the Bullet Chart.

    import{BulletChart}from'@syncfusion/ej2-charts';letbulletChart:BulletChart=newBulletChart({dataSource:[{value:270,target:250},],valueField:'value',targetField:'target',title:'Revenue',minimum:0,maximum:300,interval:50,ranges:[{end:100,color:'red'},{end:200,color:'blue'},{end:300,color:'green'}],});bulletChart.appendTo('#element');
    <!DOCTYPE html><htmllang="en"><head><title>Bullet Chart</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"/><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>

    Tooltip

    You can use tooltip for the Bullet Chart by setting theenable property to true intooltip object and by injecting theBulletTooltip module usingBulletChart.Inject(BulletTooltip) method.

    import{BulletChart,BulletTooltip}from'@syncfusion/ej2-charts';BulletChart.Inject(BulletTooltip);letbulletChart:BulletChart=newBulletChart({tooltip:{enable:true},dataSource:[{value:70,target:50}],valueField:'value',targetField:'target',animation:{enable:false},ranges:[{end:30,color:'#599C20'},{end:60,color:'#EFC820'},{end:100,color:'#CA4218'}],minimum:0,maximum:100,interval:10,title:'Revenue YTD'});bulletChart.appendTo('#element');
    <!DOCTYPE html><htmllang="en"><head><title>Bullet Chart</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"/><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