Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: "category" is not a registered scale

Tags:

chart.js

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 image 602
Pablo Avatar asked May 27 '21 18:05

Pablo


People also ask

What is the categoryscale?

What is the categoryscale? That is the default x axis type. Category scale is the scale type with labels you provide, so since he does not change the type of his x axis he is using the category scale, and because the error says so If you are using react-chartjs-2.

What is category scale in react chart?

Category scale is the scale type with labels you provide, so since he does not change the type of his x axis he is using the category scale, and because the error says so If you are using react-chartjs-2. import { Chart as ChartJS } from 'chart.js/auto' import { Chart } from 'react-chartjs-2'

How to solve “arc” is not a registered scale in a doghnut chart?

For Error: "arc" is not a registered scale in a doghnut chart, you can solve it also by import {ArcElement,Chart} from 'chart.js' and register ArcElement using Chart.register (ArcElement). We have seen how to plot doughnut and bar charts using the famous library of chart.js, and how to solve the problem of a registered scale.


Video Answer


1 Answers

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

like image 109
LeeLenalee Avatar answered Oct 28 '22 09:10

LeeLenalee