Search results

Getting Started with Vue 3 in Vue Smith Chart component

14 Oct 2021 / 6 minutes to read

This section explains how to use Smith Chart component in Vue 3 application.

Prerequisites

  • vue : 3+
  • node : 10.15+
  • vue-class-component : 8.0.0-rc.1

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.

Copied to clipboard
npm uninstall vue-cli -g

Use the following commands to install the latest version of Vue CLI.

Copied to clipboard
npm install -g @vue/cli
npm install -g @vue/cli-init

Create a new project using the command below.

Copied to clipboard
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 Preview) from the menu.

Vue 3 Terminal

Adding Syncfusion Smith Chart package in the application

Syncfusion Vue packages are maintained in the npmjs.com registry. The Smith Chart component will be used in this example. To install it in the quickstart folder use the following command.

Copied to clipboard
npm install @syncfusion/ej2-vue-charts --save

Adding Syncfusion Smith 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 Smith Chart component using following steps.

  1. Import the Smith Chart component in the <script> section of the src/App.vue file.
Copied to clipboard
<script>
import { SmithchartComponent, SmithchartLegend, TooltipRender, SeriesCollectionDirective, SeriesDirective } from "@syncfusion/ej2-vue-charts";
</script>
  1. Register the Smith 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 Smith Chart component in the following table.
Directive Name Tag Name
SeriesCollectionDirective e-seriesCollection
SeriesDirective e-series
Copied to clipboard
import { SmithchartComponent, SmithchartLegend, TooltipRender, SeriesCollectionDirective, SeriesDirective } from "@syncfusion/ej2-vue-charts";

//Component registration.
export default {
  components: {
    "ejs-smithchart": SmithchartComponent,
    "e-seriesCollection": SeriesCollectionDirective,
    "e-series" : SeriesDirective
  }
};
  1. Add the Smith Chart component definition in template section.
Copied to clipboard
<template>
   <ejs-smithchart id="smithchart" :title='title' :legendSettings='legendSettings'>
      <e-seriesCollection>
        <e-series :points='dataSource' :marker='marker' :tooltip='tooltip' :name='name' :reactance='reactance' :resistance='resistance'></e-series>
        <e-series :points='points' :tooltip='tooltip' :name='name1'></e-series>
      </e-seriesCollection>
   </ejs-smithchart>
</template>

Above is the Smith Chart component definition with title, legendsettings, series and its points, marker, tooltip, name, reactance and resistance properties.

  1. Declare the bound properties in the script section.
Copied to clipboard
export default {
  components: {
    "ejs-smithchart": SmithchartComponent,
    "e-seriesCollection": SeriesCollectionDirective,
    "e-series" : SeriesDirective
  },
  data() {
    return {
      dataSource: [
            { resistance: 0, reactance: 0.05 }, { resistance: 0, reactance: 0.05 },
            { resistance: 0, reactance: 0.05 }, { resistance: 0, reactance: 0.05 },
            { resistance: 0, reactance: 0.05 }, { resistance: 0, reactance: 0.05 },
            { resistance: 0, reactance: 0.05 }, { resistance: 0, reactance: 0.05 },
            { resistance: 0, reactance: 0.05 }, { resistance: 0, reactance: 0.05 },
            { resistance: 0.3, reactance: 0.1 }, { resistance: 0.5, reactance: 0.2 },
            { resistance: 1.5, reactance: 0.5 }, { resistance: 2.0, reactance: 0.5 },
            { resistance: 2.5, reactance: 0.4 }, { resistance: 3.5, reactance: 0.0 },
            { resistance: 2.5, reactance: 0.4 }, { resistance: 3.5, reactance: 0.0 },
            { resistance: 2.5, reactance: 0.4 }, { resistance: 3.5, reactance: 0.0 },
            { resistance: 4.5, reactance: -0.5 }, { resistance: 5.0, reactance: -1.0 }
        ],
        points: [
          { resistance: 0, reactance: 0.15 }, { resistance: 0, reactance: 0.15 },
          { resistance: 0, reactance: 0.15 }, { resistance: 0.3, reactance: 0.2 },
          { resistance: 0.3, reactance: 0.2 }, { resistance: 0.3, reactance: 0.2 },
          { resistance: 0.3, reactance: 0.2 }, { resistance: 0.3, reactance: 0.2 },
          { resistance: 0.5, reactance: 0.4 }, { resistance: 1.0, reactance: 0.8 },
          { resistance: 2.5, reactance: 1.3 }, { resistance: 3.5, reactance: 1.6 },
          { resistance: 3.5, reactance: 1.6 }, { resistance: 3.5, reactance: 1.6 },
          { resistance: 4.5, reactance: 2.0 }, { resistance: 6.0, reactance: 4.5 },
          { resistance: 8, reactance: 6 }, { resistance: 10, reactance: 25 }
        ],
        tooltip: {
          visible: true
        },
        legendSettings: {
          visible: true
        },
        marker: {
          visible: true,
          dataLabel: {
              visible: true
          }
        },
        title: { text: 'Transmission lines applied for both impedance and admittance'},
        name: 'Transmission1',
        name1: 'Transmission2',
        reactance: 'reactance',
        resistance: 'resistance'
    };
  },
  provide: {
    smithchart:[SmithchartLegend, TooltipRender]
  }
};
  1. Summarizing the above steps, update the src/App.vue file with following code.
Copied to clipboard
<template>
   <ejs-smithchart id="smithchart" :title='title' :legendSettings='legendSettings'>
      <e-seriesCollection>
        <e-series :points='dataSource' :marker='marker' :tooltip='tooltip' :name='name' :reactance='reactance' :resistance='resistance'></e-series>
        <e-series :points='points' :tooltip='tooltip' :name='name1'></e-series>
      </e-seriesCollection>
   </ejs-smithchart>
</template>

<script>
import { SmithchartComponent, SmithchartLegend, TooltipRender, SeriesCollectionDirective, SeriesDirective } from "@syncfusion/ej2-vue-charts";

export default {
  components: {
    "ejs-smithchart": SmithchartComponent,
    "e-seriesCollection": SeriesCollectionDirective,
    "e-series" : SeriesDirective
  },
  data() {
    return {
      dataSource: [
            { resistance: 0, reactance: 0.05 }, { resistance: 0, reactance: 0.05 },
            { resistance: 0, reactance: 0.05 }, { resistance: 0, reactance: 0.05 },
            { resistance: 0, reactance: 0.05 }, { resistance: 0, reactance: 0.05 },
            { resistance: 0, reactance: 0.05 }, { resistance: 0, reactance: 0.05 },
            { resistance: 0, reactance: 0.05 }, { resistance: 0, reactance: 0.05 },
            { resistance: 0.3, reactance: 0.1 }, { resistance: 0.5, reactance: 0.2 },
            { resistance: 1.5, reactance: 0.5 }, { resistance: 2.0, reactance: 0.5 },
            { resistance: 2.5, reactance: 0.4 }, { resistance: 3.5, reactance: 0.0 },
            { resistance: 2.5, reactance: 0.4 }, { resistance: 3.5, reactance: 0.0 },
            { resistance: 2.5, reactance: 0.4 }, { resistance: 3.5, reactance: 0.0 },
            { resistance: 4.5, reactance: -0.5 }, { resistance: 5.0, reactance: -1.0 }
        ],
        points: [
          { resistance: 0, reactance: 0.15 }, { resistance: 0, reactance: 0.15 },
          { resistance: 0, reactance: 0.15 }, { resistance: 0.3, reactance: 0.2 },
          { resistance: 0.3, reactance: 0.2 }, { resistance: 0.3, reactance: 0.2 },
          { resistance: 0.3, reactance: 0.2 }, { resistance: 0.3, reactance: 0.2 },
          { resistance: 0.5, reactance: 0.4 }, { resistance: 1.0, reactance: 0.8 },
          { resistance: 2.5, reactance: 1.3 }, { resistance: 3.5, reactance: 1.6 },
          { resistance: 3.5, reactance: 1.6 }, { resistance: 3.5, reactance: 1.6 },
          { resistance: 4.5, reactance: 2.0 }, { resistance: 6.0, reactance: 4.5 },
          { resistance: 8, reactance: 6 }, { resistance: 10, reactance: 25 }
        ],
        tooltip: {
          visible: true
        },
        legendSettings: {
          visible: true
        },
        marker: {
          visible: true,
          dataLabel: {
              visible: true
          }
        },
        title: { text: 'Transmission lines applied for both impedance and admittance'},
        name: 'Transmission1',
        name1: 'Transmission2',
        reactance: 'reactance',
        resistance: 'resistance'
    };
  },
  provide: {
    smithchart:[SmithchartLegend, TooltipRender]
  }
};
</script>
  1. Run the application using the following command.
Copied to clipboard
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-smith-chart-getting-started.