viser-vue: Vue.js Data Visualization Components

2.4.8 · maintenance · verified Tue Apr 21

viser-vue is a Vue.js component library designed for declarative data visualization, acting as a Vue-native wrapper for charts powered by the AntV G2 charting engine. It provides a set of components such as `<v-chart>`, `<v-tooltip>`, and various specific chart types (e.g., `<v-smooth-line>`) that allow developers to build interactive data visualizations directly within Vue templates. The package also integrates with `@antv/data-set` for robust data transformation capabilities. The current stable version is 2.4.8, last published approximately six years ago, indicating it is primarily designed for Vue 2 applications and is likely in a maintenance-only mode. Its key differentiator is providing a familiar Vue component API over the powerful G2 visualization grammar, abstracting away lower-level charting details for Vue developers. Due to its age, direct compatibility with Vue 3 is not expected.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a multi-line smooth chart using `viser-vue` components. It imports `viser-vue` as a Vue plugin, uses `@antv/data-set` to transform raw data into a suitable format, and then binds this processed data to a `<v-chart>` component, defining axes, tooltips, and a smooth line series with different colors per city. This example is designed for Vue 2 applications.

<!-- MyChart.vue -->
<template>
  <div>
    <v-chart :force-fit="true" :height="height" :data="data" :scale="scale">
      <v-tooltip />
      <v-axis />
      <v-smooth-line position="month*temperature" color="city" :size="2" />
    </v-chart>
  </div>
</template>

<script lang="ts">
import Vue from 'vue';
import ViserVue from 'viser-vue';
import DataSet from '@antv/data-set';

Vue.use(ViserVue); // Globally register ViserVue components

const sourceData = [
  { month: 'Jan', Tokyo: 7.0, London: 3.9 },
  { month: 'Feb', Tokyo: 6.9, London: 4.2 },
  { month: 'Mar', Tokyo: 9.5, London: 5.7 },
  { month: 'Apr', Tokyo: 14.5, London: 8.5 },
  { month: 'May', Tokyo: 18.4, London: 11.9 },
  { month: 'Jun', Tokyo: 21.5, London: 15.2 },
  { month: 'Jul', Tokyo: 25.2, London: 17.0 },
  { month: 'Aug', Tokyo: 26.5, London: 16.6 },
  { month: 'Sep', Tokyo: 23.3, London: 14.2 },
  { month: 'Oct', Tokyo: 18.3, London: 10.3 },
  { month: 'Nov', Tokyo: 13.9, London: 6.6 },
  { month: 'Dec', Tokyo: 9.6, London: 4.8 }
];

const dv = new DataSet.View().source(sourceData);
dv.transform({
  type: 'fold',
  fields: ['Tokyo', 'London'],
  key: 'city',
  value: 'temperature'
});
const data = dv.rows;

const scale = [{
  dataKey: 'percent',
  min: 0,
  formatter: '.2%'
}];

export default Vue.extend({
  data() {
    return {
      data,
      scale,
      height: 400
    };
  }
});
</script>

<style scoped>
/* Your styles here */
</style>

view raw JSON →