Vue Sparklines

2.0.3 · maintenance · verified Wed Apr 22

Vue Sparklines is a lightweight, TypeScript-based library providing various sparkline charts for Vue 3 applications. It offers line, curve, bar, pie, dynamic, and gradient charts, along with features like tooltips and reference lines. A key differentiator is its explicit claim of having 'no other dependencies', making it a self-contained solution for simple data visualizations. The current stable version is 2.0.3. However, it's important to note that the package was last published four years ago, suggesting a maintenance-only status rather than active development. Developers should consider this when evaluating its long-term compatibility with future Vue ecosystem changes or for projects requiring frequent updates and support.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to integrate `vue-sparklines` into a Vue 3 application, showcasing line, bar, and curve charts with sample data for dashboard metrics.

import { createApp } from 'vue';
import { Sparklines } from 'vue-sparklines';

const App = {
  template: `
    <div id="app" style="font-family: Arial, sans-serif; padding: 20px;">
      <h1>Dashboard Metrics</h1>
      <div style="display: flex; gap: 20px; flex-wrap: wrap;">
        <div style="border: 1px solid #eee; padding: 15px; border-radius: 8px; flex: 1; min-width: 250px;">
          <h2>Daily Sales</h2>
          <p>Last 7 days: <strong>{{ totalSales }} units</strong></p>
          <Sparklines :data="salesData" type="line" :height="50" :width="200" color="#4CAF50" :line-width="2" />
        </div>

        <div style="border: 1px solid #eee; padding: 15px; border-radius: 8px; flex: 1; min-width: 250px;">
          <h2>Website Visitors</h2>
          <p>Hourly: <strong>{{ totalVisitors }} unique</strong></p>
          <Sparklines :data="visitorData" type="bar" :height="50" :width="200" color="#2196F3" :bar-width="4" />
        </div>

        <div style="border: 1px solid #eee; padding: 15px; border-radius: 8px; flex: 1; min-width: 250px;">
          <h2>Server Load</h2>
          <p>Past hour: <strong>{{ currentLoad.toFixed(1) }}% average</strong></p>
          <Sparklines :data="loadData" type="curve" :height="50" :width="200" color="#FFC107" :line-width="2" />
        </div>
      </div>
    </div>
  `,
  components: {
    Sparklines,
  },
  data() {
    return {
      salesData: [12, 18, 25, 20, 30, 22, 35],
      visitorData: [50, 60, 45, 70, 55, 65, 80, 75],
      loadData: [0.1, 0.3, 0.5, 0.8, 0.7, 0.6, 0.4, 0.2, 0.15, 0.25, 0.45, 0.65]
    };
  },
  computed: {
    totalSales() {
      return this.salesData.reduce((sum: number, val: number) => sum + val, 0);
    },
    totalVisitors() {
      return this.visitorData.reduce((sum: number, val: number) => sum + val, 0);
    },
    currentLoad() {
      return this.loadData.length > 0 ? this.loadData[this.loadData.length - 1] * 100 : 0;
    }
  }
};

createApp(App).mount('#app');

view raw JSON →