vue-chrts 的 Nuxt 模块
# npm
npm install nuxt-charts
# yarn
yarn add nuxt-charts
# pnpm
pnpm add nuxt-charts
将模块添加到您的 Nuxt 配置中
// nuxt.config.ts
export default defineNuxtConfig({
modules: ["nuxt-charts"]
});
然后在您的 Nuxt 应用程序中使用这些组件
<template>
<div class="chart-wrapper">
<LineChart
:data="data"
:categories="categories"
:height="300"
:xFormatter="xFormatter"
xLabel="Month"
yLabel="Amount"
/>
</div>
</template>
<script setup>
import { LineChart } from 'vue-chrts';
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) => data[i].month;
</script>
AreaChart - 面积图AreaStackedChart - 堆叠面积图LineChart - 折线图BarChart - 柱状图DonutChart - 圆环图以下类型是自动导入的
LegendPosition(图例位置)CurveType(曲线类型)Orientation(方向)BulletLegendItemInterface(项目符号图例项接口)MIT