Vue Bar Graph Component

2.2.0 · active · verified Sun Apr 19

Vue Bar Graph is a lightweight and simple SVG component designed for creating interactive bar charts within Vue.js applications without introducing heavy third-party charting libraries. This approach significantly minimizes bundle size and external dependencies, making it ideal for projects where performance and a small footprint are critical. The current stable version, 2.2.0, is specifically built for Vue.js 3, with older 1.x versions available for Vue.js 2.x projects. The package provides features such as automatic animation on prop updates, configurable custom labels for both X and Y axes, value display, and an optional linear trendline. Its release cadence is moderate, focusing on stability, bug fixes (like reactivity issues in v2.2.0), and dependency updates, following a major migration to Vue 3 in v2.0.0. It differentiates itself through its minimalist design and direct Vue integration, avoiding the overhead of larger charting ecosystems.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to integrate `vue-bar-graph` into a Vue 3 Single File Component (SFC) using the Composition API. It showcases defining data points with custom labels, setting dimensions, enabling value display, adding a trend line, and dynamically updating the chart data, which triggers automatic animations.

<script setup>
import { ref } from 'vue';
import VueBarGraph from 'vue-bar-graph';

const chartPoints = ref([
  { label: 'Jan', value: 3 },
  { label: 'Feb', value: 5 },
  { label: 'Mar', value: 2 },
  { label: 'Apr', value: 5 },
  { label: 'May', value: 4 }
]);
const chartWidth = 600;
const chartHeight = 300;

// Example of updating data dynamically after a delay
setTimeout(() => {
  chartPoints.value = [
    { label: 'Jan', value: 10 },
    { label: 'Feb', value: 8 },
    { label: 'Mar', value: 12 },
    { label: 'Apr', value: 6 },
    { label: 'May', value: 15 },
    { label: 'Jun', value: 9 }
  ];
}, 3000);
</script>

<template>
  <div style="font-family: Arial, sans-serif; text-align: center; margin-top: 20px;">
    <h1>Sales Performance</h1>
    <p>Data will update after 3 seconds.</p>
    <vue-bar-graph
      :points="chartPoints"
      :width="chartWidth"
      :height="chartHeight"
      :show-values="true"
      :use-custom-labels="true"
      :show-trend-line="true"
      trend-line-color="#007bff"
      trend-line-width="2"
      bar-color="#42b983"
      value-color="#333"
    />
  </div>
</template>

<style>
/* No specific styles required for the component, basic layout is handled by template */
</style>

view raw JSON →