How can I help you?
Getting Started with the Vue Linear Gauge Component in Vue 3
10 Feb 202612 minutes to read
This article provides a step-by-step guide for setting up a Vite project with a JavaScript environment and integrating the Syncfusion® Vue Linear Gauge component using the Composition API / Options API.
The Composition API is a new feature introduced in Vue.js 3 that provides an alternative way to organize and reuse component logic. It allows developers to write components as functions that use smaller, reusable functions called composition functions to manage their properties and behavior.
The Options API is the traditional way of writing Vue.js components, where the component logic is organized into a series of options that define the component’s properties and behavior. These options include data, methods, computed properties, watchers, life cycle hooks, and more.
Prerequisites
Before you begin, ensure your development environment meets the following requirements:
System requirements for Syncfusion® Vue UI components
Set up the Vite project
The recommended approach to begin with Vue is to scaffold a project using Vite. To create a new Vite project, use one of the commands specific to either npm or Yarn.
npm create vite@latestor
yarn create viteThe above commands will prompt you to configure the project. Follow these steps:
- Define the project name: Specify the name of the project as
my-projectfor this article.
? Project name: » my-project- Select
Vueas the framework to create a Vue 3 project.
? Select a framework: » - Use arrow-keys. Return to submit.
Vanilla
> Vue
React
Preact
Lit
Svelte
Others- Choose
JavaScriptas the framework variant to build the Vite project using JavaScript and Vue.
? Select a variant: » - Use arrow-keys. Return to submit.
> JavaScript
TypeScript
Customize with create-vue ↗
Nuxt ↗- After creating
my-project, run the following command to install dependencies:
cd my-project
npm installor
cd my-project
yarn installProceed to add Syncfusion® components to the project.
Add Syncfusion® Vue packages
Syncfusion® Vue component packages are available at npmjs.com. To use Syncfusion® Vue components in the project, install the corresponding npm package.
This article uses the Vue Linear Gauge component as an example. To use the Vue Linear Gauge component in the project, install the package using the following command:
npm install @syncfusion/ej2-vue-lineargauge --saveor
yarn add @syncfusion/ej2-vue-lineargaugeAdd Syncfusion® Vue component
Follow the steps below to add the Vue Linear Gauge component using Composition API or Options API:
1.First, import and register the Linear Gauge component and its child directives in the script section of the src/App.vue file. If you are using the Composition API, you should add the setup attribute to the script tag to indicate that Vue will be using the Composition API.
<script setup>
import { LinearGaugeComponent as EjsLineargauge, AxesDirective as EAxes, AxisDirective as EAxis, PointersDirective as EPointers, PointerDirective as EPointer, RangesDirective as ERanges, RangeDirective as ERange } from '@syncfusion/ej2-vue-lineargauge';
</script><script>
import { LinearGaugeComponent, AxesDirective, AxisDirective, PointersDirective, PointerDirective, RangesDirective, RangeDirective } from '@syncfusion/ej2-vue-lineargauge';
//Component registration
export default {
name: "App",
components: {
'ejs-lineargauge' : LinearGaugeComponent,
'e-axes' : AxesDirective,
'e-axis' : AxisDirective,
'e-pointers': PointersDirective,
'e-pointer' : PointerDirective,
'e-ranges' : RangesDirective,
'e-range' : RangeDirective
}
}
</script>2.In the template section, define the Linear Gauge component with the axis, pointer and range property definitions.
<template>
<ejs-lineargauge :title ='title' orientation='Horizontal'>
<e-axes>
<e-axis minimum=0 maximum=200>
<e-pointers>
<e-pointer value=140 color='red'></e-pointer>
</e-pointers>
<e-ranges>
<e-range start=0 end=80 startWidth=15 endWidth=15></e-range>
<e-range start=80 end=120 startWidth=15 endWidth=15></e-range>
<e-range start=120 end=140 startWidth=15 endWidth=15></e-range>
<e-range start=140 end=200 startWidth=15 endWidth=15></e-range>
</e-ranges>
</e-axis>
</e-axes>
</ejs-lineargauge>
</template>3.In the script section, declare the values for the properties defined in the template section.
<script setup>
const title = "Linear Gauge";
</script><script>
data() {
return {
title: 'Linear Gauge'
};
}
</script>Here is the complete code for the above steps in the src/App.vue file:
<template>
<ejs-lineargauge :title ='title' orientation='Horizontal'>
<e-axes>
<e-axis minimum=0 maximum=200>
<e-pointers>
<e-pointer value=140 color='red'></e-pointer>
</e-pointers>
<e-ranges>
<e-range start=0 end=80 startWidth=15 endWidth=15></e-range>
<e-range start=80 end=120 startWidth=15 endWidth=15></e-range>
<e-range start=120 end=140 startWidth=15 endWidth=15></e-range>
<e-range start=140 end=200 startWidth=15 endWidth=15></e-range>
</e-ranges>
</e-axis>
</e-axes>
</ejs-lineargauge>
</template>
<script setup>
import { LinearGaugeComponent as EjsLineargauge, AxesDirective as EAxes, AxisDirective as EAxis, PointersDirective as EPointers, PointerDirective as EPointer, RangesDirective as ERanges, RangeDirective as ERange } from '@syncfusion/ej2-vue-lineargauge';
const title = "Linear Gauge";
</script><template>
<ejs-lineargauge :title ='title' orientation='Horizontal'>
<e-axes>
<e-axis minimum=0 maximum=200>
<e-pointers>
<e-pointer value=140 color='red'></e-pointer>
</e-pointers>
<e-ranges>
<e-range start=0 end=80 startWidth=15 endWidth=15></e-range>
<e-range start=80 end=120 startWidth=15 endWidth=15></e-range>
<e-range start=120 end=140 startWidth=15 endWidth=15></e-range>
<e-range start=140 end=200 startWidth=15 endWidth=15></e-range>
</e-ranges>
</e-axis>
</e-axes>
</ejs-lineargauge>
</template>
<script>
import { LinearGaugeComponent, AxesDirective, AxisDirective, PointersDirective, PointerDirective, RangesDirective, RangeDirective } from '@syncfusion/ej2-vue-lineargauge';
// Component registration
export default {
name: "App",
// Declaring component and its directives
components: {
'ejs-lineargauge' : LinearGaugeComponent,
'e-axes' : AxesDirective,
'e-axis' : AxisDirective,
'e-pointers': PointersDirective,
'e-pointer' : PointerDirective,
'e-ranges' : RangesDirective,
'e-range' : RangeDirective
},
// Bound properties declarations
data() {
return {
title: 'Linear Gauge'
};
}
};
</script>Run the project
To run the project, use the following command:
npm run devor
yarn run devThe output will appear as follows:

Sample: vue3-linear-gauge-getting-started.