错误:“类别"不是注册规模 [英] Error: "category" is not a registered scale
问题描述
我正在尝试将 Chart.js 从 2.9.3
迁移到 3.3.0
甚至在应用更改之后 (https://www.chartjs.org/docs/latest/getting-started/v3-migration.html)我仍然收到错误:
错误:类别"不是注册规模
.
这就是我所拥有的
Chart.register(BarController, DoughnutController, LineController, PieController);
new Chart(this.id, {类型:'酒吧',数据,选项: {响应式:真实,保持纵横比:假,插件:{标题: {显示:options.plugins.title ?真假,},工具提示:{模式:'索引',相交:假},秤:{X: {堆叠:真实,网格线: {画框:假,显示:假,},滴答声:{自动跳过:真,maxTicksLimit: 13,},},是:{堆叠:真实,网格线: {颜色:'#e6e6e6',画框:假,},}}});
我会在这里遗漏什么?
就像错误说你正在使用 category scale
所以你需要像这样导入和注册它:import{CategoryScale} 来自chart.js";Chart.register(CategoryScale)
.
或者您可以选择不使用 treeshaking 并像这样导入所有内容:import Chart from 'chart.js/auto'
.
对于您可能需要导入和注册的所有可用内容,请查看此处:https://www.chartjs.org/docs/3.3.0/getting-started/integration.html#bundlers-webpack-rollup-etcp>
I'm trying to migrate Chart.js from 2.9.3
to 3.3.0
and even after applying the the changes (https://www.chartjs.org/docs/latest/getting-started/v3-migration.html) I'm still getting the error:
Error: "category" is not a registered scale
.
This is what I have
Chart.register(BarController, DoughnutController, LineController, PieController);
new Chart(this.id, {
type: 'bar',
data,
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
title: {
display: options.plugins.title ? true : false,
},
tooltip: {
mode: 'index',
intersect: false
},
scales: {
x: {
stacked: true,
gridLines: {
drawBorder: false,
display: false,
},
ticks: {
autoSkip: true,
maxTicksLimit: 13,
},
},
y: {
stacked: true,
gridLines: {
color: '#e6e6e6',
drawBorder: false,
},
}
}
});
What could I be missing here?
Like the error says you are using the category scale
so you will need to import and register it like so: import {CategoryScale} from 'chart.js'; Chart.register(CategoryScale)
.
Or you can choose to not use treeshaking and import everything like so: import Chart from 'chart.js/auto'
.
For all available things you might need to import and register please take a look here: https://www.chartjs.org/docs/3.3.0/getting-started/integration.html#bundlers-webpack-rollup-etc
这篇关于错误:“类别"不是注册规模的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!