score:9

Accepted answer

chart.js 3 is tree-shakeable, so it is necessary to import and register the controllers, elements, scales and plugins you are going to use.

please take a look at bundlers (webpack, rollup, etc.) from the chart.js documentation.

in your case, this could be done as follows ():

import { chart, barelement, barcontroller, categoryscale, decimation, filler, legend, title, tooltip} from 'chart.js';

export class mychartcomponent implements oninit {
  
    constructor() {
        chart.register(barelement, barcontroller, categoryscale, decimation, filler, legend, title, tooltip);
    }
    ...
}

score:2

i have the same problem, i fixed it this way. use this:

import chart from 'chart.js/auto';

instead of this:

import { chart } from 'node_modules/chart.js';

score:22

import { chart, registerables} from 'chart.js';

chart.register(...registerables);


Related Query

More Query from same tag