react-chartjs-2错误(显示白色屏幕)

ndasle7k  于 2022-11-06  发布在  Chart.js
关注(0)|答案(1)|浏览(145)

我在尝试使用react-chartjs-2添加图表时遇到此错误。
Error Log
这是我的代码:

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;

这是chart.js和react-chartjs-2的版本
“文件名:“^3.8.0,”
“React”:“^18.1.0”,
“React图表-2”:“^4.1.0”

qzwqbdag

qzwqbdag1#

尝试导入并注册它们

import {
  ArcElement,
  Chart as ChartJS,
  Legend as ChartjsLegend,
  Tooltip,
  TooltipItem,
  TooltipModel,
} from 'chart.js';

ChartJS.register(ArcElement, Tooltip,ChartjsLegend);

相关问题