Nuxt Charts

2.1.4 · active · verified Sun Apr 19

Nuxt Charts is a Nuxt 3 module (current stable version 2.1.4) that provides an effortless way to integrate beautiful and responsive charting components into Nuxt applications. It acts as a wrapper around the `vue-chrts` library, which is inspired by Tremor and built on top of Unovis, offering a variety of chart types including Line, Bar, Area, Stacked Area, and Donut charts. The module leverages Nuxt's auto-import feature for its components and types, simplifying the development experience. It is designed with Vue 3 and TypeScript, focusing on customizability and an intuitive API. While `nuxt-charts` doesn't have a fixed public release cadence, it typically aligns with the Nuxt ecosystem's rapid development. Its key differentiator lies in providing a 'Nuxt-native' charting solution, abstracting away direct component imports from `vue-chrts` and integrating seamlessly with the Nuxt development workflow, which differentiates it from general Vue charting libraries like `vue-chartjs` or `vue-chartkick`.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to enable the `nuxt-charts` module in `nuxt.config.ts` and then use both `LineChart` and `BarChart` components directly in a Vue component. It highlights the auto-import functionality for chart components and provides example data and categories.

// nuxt.config.ts
export default defineNuxtConfig({
  modules: [
    'nuxt-charts'
  ]
});

// app.vue (or any Nuxt page/component)
<template>
  <div class="chart-wrapper">
    <LineChart
      :data="data"
      :categories="categories"
      :height="300"
      :xFormatter="xFormatter"
      xLabel="Month"
      yLabel="Amount"
    />
    <BarChart
      :data="barData"
      :categories="barCategories"
      :height="250"
      xLabel="Product"
      yLabel="Revenue"
    />
  </div>
</template>

<script setup lang="ts">
// Chart components like LineChart and BarChart are auto-imported by the Nuxt module

const data = [
  { month: 'Jan', sales: 100, profit: 50 },
  { month: 'Feb', sales: 120, profit: 55 },
  { month: 'Mar', sales: 180, profit: 80 },
  { month: 'Apr', sales: 110, profit: 40 },
  { month: 'May', sales: 90, profit: 30 }
];

const categories = {
  sales: {
    name: 'Sales',
    color: '#3b82f6'
  },
  profit: {
    name: 'Profit',
    color: '#10b981'
  }
};

const xFormatter = (i: number) => data[i].month;

const barData = [
  { product: 'A', revenue: 200 },
  { product: 'B', revenue: 300 },
  { product: 'C', revenue: 150 }
];

const barCategories = {
  revenue: {
    name: 'Total Revenue',
    color: '#fbbf24'
  }
};
</script>

<style scoped>
.chart-wrapper {
  max-width: 800px;
  margin: 2rem auto;
  padding: 1rem;
  border: 1px solid #eee;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}
</style>

view raw JSON →