ChartJS 图表无法呈现空白页面,但条形图组件可以正常工作

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

我试图呈现一个简单的图表,它是工作正常的酒吧组件,但当我改变到甜甜圈组件或任何其他组件,然后它呈现一个空白的白色页面

import { Box } from "@chakra-ui/react";
import React from "react";

import { Pie, Bar, Line, Doughnut } from "react-chartjs-2";

function Donutchart() {
  return (
    <Box maxH={400} maxWidth={600}>
      <Doughnut
        options={{
          responsive: true,
          plugins: {
            title: {
              display: false,
            },
          },
          maintainAspectRatio: false,
        }}
        data={{
          labels: ["Energy", "envi", "retail", "govt"],
          datasets: [
            {
              label: "Sector",
              data: [54, 36, 12, 45],
              backgroundColor: "rgba(53, 162, 235, 0.5)",
            },
          ],
        }}
        height={400}
        width={600}
      />
    </Box>
  );
}
export default Donutchart;
kiayqfof

kiayqfof1#

也可以尝试这样导入寄存器

import {
  Chart as ChartJS,
  CategoryScale,
  LinearScale,
  BarElement,
  Title,
  Tooltip,
  Legend,
} from 'chart.js';

ChartJS.register(
  CategoryScale,
  LinearScale,
  BarElement,
  Title,
  Tooltip,
  Legend
);

我希望这对你有帮助

相关问题