Skip to content

Latest commit

 

History

History
231 lines (161 loc) · 7.61 KB

File metadata and controls

231 lines (161 loc) · 7.61 KB
layout post
title Getting started with
description Checkout and learn about Getting started with
platform ej2-javascript
control Getting started
publishingplatform
documentation ug
domainurl

Getting started in ##Platform_Name## Bullet chart control

This section explains how to create a simple Bullet chart and configure its available functionalities in TypeScript using Essential JS 2 quickstart seed repository.

This application is integrated with the webpack.config.js configuration and uses the latest version of the webpack-cli. It requires node v14.15.0 or higher. For more information about webpack and its features, refer to the webpack 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 from GitHub.

{% tabs %} {% highlight bash tabtitle="CMD" %}

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

{% endhighlight %} {% endtabs %}

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

{% tabs %} {% highlight bash tabtitle="CMD" %}

cd ej2-quickstart

{% endhighlight %} {% endtabs %}

Add Syncfusion JavaScript packages

Syncfusion JavaScript (Essential JS 2) packages are available on the npmjs.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.

{% tabs %} {% highlight bash tabtitle="NPM" %}

npm install

{% endhighlight %} {% endtabs %}

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 its id attribute as element in your ~/src/index.html file to initialize the Bullet chart.

{% tabs %} {% highlight html tabtitle="index.html" %}

<title>EJ2 Bullet Chart</title> .... ....

{% endhighlight %} {% endtabs %}

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

{% tabs %} {% highlight ts tabtitle="app.ts" %}

import { BulletChart } from '@syncfusion/ej2-charts';

// initialize BulletChart component let bulletChart: BulletChart = new BulletChart();

// render initialized Bullet Chart bulletChart.appendTo('#element');

{% endhighlight %} {% endtabs %}

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

{% tabs %} {% highlight bash tabtitle="NPM" %}

npm run start

{% endhighlight %} {% endtabs %}

The below example shows a basic Chart.

{% tabs %} {% highlight ts tabtitle="index.ts" %} {% include code-snippet/bullet-chart/getting-started-cs6/index.ts %} {% endhighlight %} {% highlight html tabtitle="index.html" %} {% include code-snippet/bullet-chart/getting-started-cs6/index.html %} {% endhighlight %} {% endtabs %}

{% previewsample "page.domainurl/code-snippet/bullet-chart/getting-started-cs6" %}

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 using BulletChart.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 using BulletChart.Inject method.

{% tabs %} {% highlight ts tabtitle="app.ts" %}

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

{% endhighlight %} {% endtabs %}

BulletChart With Data

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

{% tabs %} {% highlight ts tabtitle="app.ts" %}

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

{% endhighlight %} {% endtabs %}

Now assign the local data to dataSource property. value and target values should be mapped with valueField and targetField respectively.

{% tabs %} {% highlight ts tabtitle="index.ts" %} {% include code-snippet/bullet-chart/getting-started-cs7/index.ts %} {% endhighlight %} {% highlight html tabtitle="index.html" %} {% include code-snippet/bullet-chart/getting-started-cs7/index.html %} {% endhighlight %} {% endtabs %}

{% previewsample "page.domainurl/code-snippet/bullet-chart/getting-started-cs7" %}

Add Bullet Chart Title

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

{% tabs %} {% highlight ts tabtitle="index.ts" %} {% include code-snippet/bullet-chart/getting-started-cs8/index.ts %} {% endhighlight %} {% highlight html tabtitle="index.html" %} {% include code-snippet/bullet-chart/getting-started-cs8/index.html %} {% endhighlight %} {% endtabs %}

{% previewsample "page.domainurl/code-snippet/bullet-chart/getting-started-cs8" %}

Ranges

You can add a range using ranges property to the Bullet Chart.

{% tabs %} {% highlight ts tabtitle="index.ts" %} {% include code-snippet/bullet-chart/getting-started-cs9/index.ts %} {% endhighlight %} {% highlight html tabtitle="index.html" %} {% include code-snippet/bullet-chart/getting-started-cs9/index.html %} {% endhighlight %} {% endtabs %}

{% previewsample "page.domainurl/code-snippet/bullet-chart/getting-started-cs9" %}

Tooltip

You can use tooltip for the Bullet Chart by setting the enable property to true in tooltip object and by injecting the BulletTooltip module using BulletChart.Inject(BulletTooltip) method.

{% tabs %} {% highlight ts tabtitle="index.ts" %} {% include code-snippet/bullet-chart/getting-started-cs10/index.ts %} {% endhighlight %} {% highlight html tabtitle="index.html" %} {% include code-snippet/bullet-chart/getting-started-cs10/index.html %} {% endhighlight %} {% endtabs %}

{% previewsample "page.domainurl/code-snippet/bullet-chart/getting-started-cs10" %}