Getting Started with Syncfusion Bullet Chart component in Vue 3
20 Mar 20236 minutes to read
This section explains how to use Bullet Chart component in Vue 3 application.
Prerequisites
System requirements for Syncfusion Vue UI components
Creating Vue application using Vue CLI
The easiest way to create a Vue application is to use the Vue CLI
. Vue CLI versions above 4.5.0
are mandatory for creating applications using Vue 3. Use the following command to uninstall older versions of the Vue CLI.
npm uninstall vue-cli -g
Use the following commands to install the latest version of Vue CLI.
npm install -g @vue/cli
npm install -g @vue/cli-init
Create a new project using the command below.
vue create quickstart
Initiating a new project prompts us to choose the type of project to be used for the current application. Select the option Default (Vue 3)
from the menu.
Adding Syncfusion Bullet Chart package in the application
Syncfusion Vue packages are maintained in the npmjs.com
registry. The Bullet Chart component will be used in this example. To install it in the quickstart folder use the following command.
npm install @syncfusion/ej2-vue-charts --save
Adding Syncfusion Bullet Chart component in the application
You have completed all the necessary configurations needed for rendering the Syncfusion Vue component. Now, you are going to add the Bullet Chart component using following steps.
-
Import the Bullet Chart component in the
<script>
section of thesrc/App.vue
file.<script> import { BulletChartComponent, BulletTooltip, BulletRangeCollectionDirective, BulletRangeDirective } from "@syncfusion/ej2-vue-charts"; </script>
-
Register the Bullet Chart component along with the required child directives which are used in this example. Find the list of child directives and tag names that can be used in the Bullet Chart component in the following table.
Directive Name Tag Name BulletRangeCollectionDirective
e-bullet-range-collection
BulletRangeDirective
e-bullet-range
import { BulletChartComponent, BulletTooltip, BulletRangeCollectionDirective, BulletRangeDirective } from "@syncfusion/ej2-vue-charts"; //Component registration. export default { components: { "ejs-bulletchart": BulletChartComponent, "e-bullet-range-collection": BulletRangeCollectionDirective, "e-bullet-range": BulletRangeDirective } };
-
Add the Bullet Chart component definition in template section.
<template> <ejs-bulletchart :dataSource="data" :valueField="valueField" :tooltip="tooltip" :targetField="targetField" :height="height" :title="title" :minimum="minimum" :maximum="maximum" :interval="interval"> <e-bullet-range-collection> <e-bullet-range end="100" color="red"></e-bullet-range> <e-bullet-range end="200" color="blue"></e-bullet-range> <e-bullet-range end="300" color="green"></e-bullet-range> </e-bullet-range-collection> </ejs-bulletchart> </template>
Above is the Bullet Chart component definition with
dataSource
,valueField
,tooltip
,targetField
,height
,minimum
,maximum
,interval
andranges
properties. -
Declare the bound properties in the
script
section.export default { components: { "ejs-bulletchart": BulletChartComponent, "e-bullet-range-collection": BulletRangeCollectionDirective, "e-bullet-range": BulletRangeDirective }, data() { return { data: [ { value: 100, target: 80 }, { value: 200, target: 180 }, { value: 300, target: 280 }, { value: 400, target: 180 }, { value: 500, target: 230 } ], minimum: 0, maximum: 300, interval: 50, tooltip: { enable: true }, title: 'Revenue', height: '300px', targetField: 'target', valueField: 'value' }; }, provide: { bulletChart: [BulletTooltip] } };
-
Summarizing the above steps, update the
src/App.vue
file with following code.<template> <ejs-bulletchart :dataSource="data" :valueField="valueField" :tooltip="tooltip" :targetField="targetField" :height="height" :title="title" :minimum="minimum" :maximum="maximum" :interval="interval"> <e-bullet-range-collection> <e-bullet-range end="100" color="red"></e-bullet-range> <e-bullet-range end="200" color="blue"></e-bullet-range> <e-bullet-range end="300" color="green"></e-bullet-range> </e-bullet-range-collection> </ejs-bulletchart> </template> <script> import { BulletChartComponent, BulletTooltip, BulletRangeCollectionDirective, BulletRangeDirective } from "@syncfusion/ej2-vue-charts"; export default { components: { "ejs-bulletchart": BulletChartComponent, "e-bullet-range-collection": BulletRangeCollectionDirective, "e-bullet-range": BulletRangeDirective }, data() { return { data: [ { value: 100, target: 80 }, { value: 200, target: 180 }, { value: 300, target: 280 }, { value: 400, target: 180 }, { value: 500, target: 230 } ], minimum: 0, maximum: 300, interval: 50, tooltip: { enable: true }, title: 'Revenue', height: '300px', targetField: 'target', valueField: 'value' }; }, provide: { bulletChart: [BulletTooltip] } }; </script>
-
Run the application using the following command.
npm run serve
The web server will be initiated and open the quickstart app in the browser at port localhost:8080
Refer the following sample, vue3-bullet-chart-getting-started.