Closed HoangMinh991 closed 3 years ago
Hi @HoangMinh991,
Recently I encountered this problem and could solve without significant effort.
The reason of the problem is breaking change in v3, ChartJS.plugins.register
was replaced by ChartJS.register
, therefore you can do this trick to solve the issue.
import { ChartJSNodeCanvas } from 'chartjs-node-canvas';
const canvas = new ChartJSNodeCanvas({
width: 700,
height: 400,
chartCallback: (ChartJS) => {
/** Add plugins here **/
ChartJS.register(require('chartjs-plugin-datalabels'))
}
});
Hope this helped you!
Regards, Aren Hovsepyan
I have not yet looked at officially supporting 3.x.x
yet (hence the peer dependency of ^2.7.3
), but it seems like Aren's fix should work. Thanks for posting @Cartman720 ! I will look at trying to support v3 soon
ChartJS.plugins.register not working with chartjs 3.x version , it only working with 2.x version UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'register' of undefined