Chart.register 不是一个函数(vue-chartjs 官方例子不工作)

问题描述 投票:0回答:0

我正在尝试在我的 nuxt 2 项目中使用官方的“vue-charts.js”文档示例:

<template>
  <Bar
    id="my-chart-id"
    :options="chartOptions"
    :data="chartData"
  />
</template>

<script>
import { Bar } from 'vue-chartjs'
import { Chart as ChartJS, Title, Tooltip, Legend, BarElement, CategoryScale, LinearScale } from 'chart.js'

ChartJS.register(Title, Tooltip, Legend, BarElement, CategoryScale, LinearScale)

export default {
  name: 'BarChart',
  components: { Bar },
  data() {
    return {
      chartData: {
        labels: [ 'January', 'February', 'March' ],
        datasets: [ { data: [40, 20, 12] } ]
      },
      chartOptions: {
        responsive: true
      }
    }
  }
}
</script>

但是我得到

chart_js__WEBPACK_IMPORTED_MODULE_1__.Chart.register is not a function
错误。我做错了什么?

补充资料:

"nuxt": "^2.15.7", "vue-chartjs": "^5.2.0", “图表.js”:“^4.2.1”

vue.js charts nuxt.js vue-chartjs
© www.soinside.com 2019 - 2024. All rights reserved.