带有Line组件的Vue Chart.JS:未捕获的错误:类没有ID:[对象对象]

sirbozc5  于 2023-10-18  发布在  Chart.js
关注(0)|答案(1)|浏览(162)

我在使用Line组件时遇到了这个异常。有了酒吧就行了。

core.typedRegistry.js:38 Uncaught Error: class does not have id: [object Object]
    at TypedRegistry.register (core.typedRegistry.js:38:13)
    at Registry._exec (core.registry.js:154:14)
    at core.registry.js:142:16
    at each (helpers.core.ts:156:10)
    at core.registry.js:134:9
    at Array.forEach (<anonymous>)
    at Registry._each (core.registry.js:125:15)
    at Registry.add (core.registry.js:26:10)
    at Chart.register (core.controller.js:131:14)
    at Chart.vue:7:9

下面是我的组件:

<script type="module">

import { Line } from 'vue-chartjs'
import { Chart as ChartJS, Title, Tooltip, Legend, BarElement, PointElement , CategoryScale, LinearScale } from 'chart.js'

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

export default {

            data() {
                return {

                   chartData: {
                        labels: [ 'January', 'February', 'March' ],
                        datasets: [ { 
                            label:"Ventes",
                            backgroundColor: 'rgb(255, 99, 132)',
                            borderColor: 'rgb(255, 99, 132)', 
                            data: [40, 20, 12] } ]
                    },
                    chartOptions: {
                        responsive: true
                    }
        
                }
              
            }

            ,

             components: {
                Line
            }

}

</script>

<template>

    <!-- Page Heading -->
    <h1  style = "text-align:center">Graphiques</h1>

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

</template>

有什么想法吗?
Stackoverflow说:看起来你的帖子大部分都是代码;请补充一些细节。
所以我会在这里写一些blablabla
blablabla blablabla blablabla blablabla blablabla blablabla blablabla
谢谢

bfrts1fy

bfrts1fy1#

答案已经在评论中公布了:
您仍在导入BarElement。尝试导入以下项目,并注册它们:从'chart.js'导入{ Chart as ChartJS,CategoryScale,LinearScale,PointElement,LineElement,Title,Tooltip,Legend }
它工作

相关问题