Getting Started with Syncfusion Range Navigator component in Vue 3

23 Mar 20236 minutes to read

This section explains how to use Range Navigator 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.

Vue 3 Terminal

Adding Syncfusion Range Navigator package in the application

Syncfusion Vue packages are maintained in the npmjs.com registry. The Range Navigator 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 Range Navigator 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 Range Navigator component using following steps.

1. Import the Range Navigator component in the <script> section of the src/App.vue file.

  <script>
  import { RangeNavigatorComponent, StepLineSeries, DateTime, RangenavigatorSeriesCollectionDirective,
  RangenavigatorSeriesDirective } from "@syncfusion/ej2-vue-charts";
  </script>

2. Register the Range Navigator component along with the required child directives which are used in this example. Find the list of child directives and the tag names that can be used in the Range Navigator component in the following table.

Directive Name Tag Name
RangenavigatorSeriesCollectionDirective e-rangenavigator-series-collection
RangenavigatorSeriesDirective e-rangenavigator-series
  import { RangeNavigatorComponent, StepLineSeries, DateTime, RangenavigatorSeriesCollectionDirective,
  RangenavigatorSeriesDirective } from "@syncfusion/ej2-vue-charts";
  //Component registeration.
  export default {
      name: "App",
      components: {
      "ejs-rangenavigator": RangeNavigatorComponent,
      "e-rangenavigator-series-collection": RangenavigatorSeriesCollectionDirective,
      "e-rangenavigator-series":  RangenavigatorSeriesDirective
    },
  };

In the above code snippet, you have registered Range Navigator and the directives for series. Series directives are used to visualize the data with different chart types like Line, StepLine etc.

3. Add the component definition in template section.

  <template>
      <ejs-rangenavigator :valueType='valueType' :value='value' :labelFormat='labelFormat'>
          <e-rangenavigator-series-collection>
              <e-rangenavigator-series :dataSource='data' type='StepLine' xName='Date' yName='Close' width=2>
              </e-rangenavigator-series>
          </e-rangenavigator-series-collection>
      </ejs-rangenavigator>
  </template>

Above is the Range Navigator component with dataSource bound to series directives.

4. Define the collection data which is bound for the dataSource, valueType, value and labelFormat properties in the script section.

    data() {
      return {
      valueType: 'DateTime',
      value: [new Date("2008-01-01"), new Date("2010-01-01")],
      labelFormat: 'MMM-yy',
      data:[
          { Date: new Date("2005-01-01"), Close: 21 },
          { Date: new Date("2006-01-01"), Close: 24 },
          { Date: new Date("2007-01-01"), Close: 36 },
          { Date: new Date("2008-01-01"), Close: 38 },
          { Date: new Date("2009-01-01"), Close: 54 },
          { Date: new Date("2010-01-01"), Close: 57 },
          { Date: new Date("2011-01-01"), Close: 62 },
        ],
      };
    },

5. Summarizing the above steps, update the src/App.vue file with following code.

  <template>
      <ejs-rangenavigator :valueType='valueType' :value='value' :labelFormat='labelFormat'>
          <e-rangenavigator-series-collection>
              <e-rangenavigator-series :dataSource='data' type='StepLine' xName='Date' yName='Close' width=2>
              </e-rangenavigator-series>
          </e-rangenavigator-series-collection>
      </ejs-rangenavigator>
  </template>

  <script>
  import { RangeNavigatorComponent, StepLineSeries, DateTime, RangenavigatorSeriesCollectionDirective,
  RangenavigatorSeriesDirective } from "@syncfusion/ej2-vue-charts";

  export default {
      name: "App",
      components: {
      "ejs-rangenavigator": RangeNavigatorComponent,
      "e-rangenavigator-series-collection": RangenavigatorSeriesCollectionDirective,
      "e-rangenavigator-series":  RangenavigatorSeriesDirective
    },
    data() {
      return {
      valueType: 'DateTime',
      value: [new Date("2008-01-01"), new Date("2010-01-01")],
      labelFormat: 'MMM-yy',
      data:[
          { Date: new Date("2005-01-01"), Close: 21 },
          { Date: new Date("2006-01-01"), Close: 24 },
          { Date: new Date("2007-01-01"), Close: 36 },
          { Date: new Date("2008-01-01"), Close: 38 },
          { Date: new Date("2009-01-01"), Close: 54 },
          { Date: new Date("2010-01-01"), Close: 57 },
          { Date: new Date("2011-01-01"), Close: 62 },
        ],
      };
    },
    provide: {
      rangeNavigator: [ DateTime, StepLineSeries ],
    },
  };
  </script>

6. 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.

Output

Refer the following sample, vue3-range-navigator-getting-started.