Vue.js

zingchart-vue is a Vue.js directive to allow ZingChart to work dynamically with data. Quickly add charts to your Vue application with our ZingChart component. This guide assumes some basic working knowledge of Vue. You can view the full component on GitHub or NPM.

1. Install

Install the zingchart package via npm:

$ npm install zingchart

Install the zingchart-vue package via npm:

$ npm install zingchart-vue

2. Include the component in your project

You can either include the zingchart-vue component to your project globally or locally per component

Globally

In your main app file, add the following lines of code:

import { createApp } from 'vue';
import App from './App.vue';
import ZingChartVue from './ZingChart.vue';

const app = createApp(App);
app.component('ZingChartVue', ZingChartVue);
app.mount('#app');

This will register the zingchart component globally throughout your application. While the easiest installation option, this will load ZingChart immediately on your user's first load of the application - regardless if a chart is on the first page or not. We recommend this approach if ZingChart is used heavily across multiple pages.

Locally per component

In each component where ZingChart is being used, include the following in your component's configuration:

import ZingChartVue from 'zingchart-vue';

We recommend this approach if ZingChart is only included in a few, un-related pages across your application.

Usage

The zingchart-vue component can be included into a template as an element. Below is a simple example of a line chart:

<ZingChartVue :data="chartData" />
let chartData = {
    type: 'line',
    series: [{
        values: [4,5,3,3,4,4]
    }]
};

Parameters

data [object]

<ZingChartVue :data="myData" :series="mySeries" />
let myData = {
    type: 'line',
    title: {
        text: 'Hello World',
    },
};

let mySeries: [
    { values: [1,2,4,5,6] }
];

id [string] (optional)

The id for the DOM element for ZingChart to attach to. If no id is specified, the id will be autogenerated in the form of zingchart-auto-#

output [string] (optional)

The render type for the visualization, either svg (default) or canvas

series [array] (optional)

Accepts an array of series objects, and overrides a series if it was supplied into the config object. Varies by chart type used - Refer to the ZingChart documentation for more details.

<ZingChartVue :data="myData" :series="mySeries" />
let myData = {
    type: 'line',
    title: {
        text: 'Hello World',
    },
};

let mySeries: [{
    values: [1,2,4,5,6]
}];

width [string or number] (optional)

The width of the chart. Defaults to 100%

height [string or number] (optional)

The height of the chart. Defaults to 480px.

theme [object] (optional)

The theme or 'defaults' object defined by ZingChart. More information available here: https://www.zingchart.com/docs/api/themes

Events

All zingchart events are readily available on the component to listen to. For example, to listen for the 'complete' event when the chart is finished rendering:

<ZingChartVue :data="myData" @complete="chartCompleted" />
function chartCompleted(result) {
    console.log(`The chart ${result.id} finished rendering`);
};

For a list of all the events that you can listen to, refer to the complete documentation on https://www.zingchart.com/docs/events

Note that the event names are translated to camel-case:

  • complete => @complete
  • node_mouseover => @nodeMouseover
  • legend_marker_click => @legendMarkerClick

Methods

All zingchart methods are readily available on the component's instance to call. For example, to add a new plot node to the chart:

<ZingChartVue :data="myData" ref="chart"/>
const chart = ref();

function myCustomAddNode() {
    chart.value.addnode({
        value: 55,
    });
}

function myCustomMapZoom() {
    // Example of usage when method name contains member (.) operator
    chart.value['zingchart.maps.viewAll']({
        value: 55,
    });
}

For a list of all the methods that you can call and the parameters each method can take, refer to the ZingChart Method Reference.

Still Using Vue 2?

The zingchart-vue wrapper for Vue 2 can be located here.