I am getting this error while trying to add chart using react-chartjs-2.
This is my code:
import { Doughnut } from 'react-chartjs-2';
const data = {
labels: ['Red', 'Blue', 'Yellow'],
datasets: [
{
data: [12, 15, 5],
},
],
};
function App() {
return (
<>
<Doughnut data={data} />
</>
);
}
export default App;
This is the version of chart.js and react-chartjs-2
"chart.js": "^3.8.0",
"react": "^18.1.0",
"react-chartjs-2": "^4.1.0"
try to import this and register them
import {
ArcElement,
Chart as ChartJS,
Legend as ChartjsLegend,
Tooltip,
TooltipItem,
TooltipModel,
} from 'chart.js';
ChartJS.register(ArcElement, Tooltip,ChartjsLegend);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.