How to import chart.js 3+ into React application?

Viewed 2625

I have a trouble importing chart.js into my application, while in version 2+ it was simple as:

import Chartjs from 'chart.js';

Now this doesn't work anymore.

Attempted import error: 'chart.js' does not contain a default export (imported as 'Chartjs').
2 Answers

Ok, I found the answer. You have to import everything by parts and then register it.

import { Chart, PieController, ArcElement, Legend, Tooltip, Title } from 'chart.js';

Chart.register(PieController, ArcElement, Title, Legend, Tooltip);
Related