📜  react chart.js - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:01.793000             🧑  作者: Mango

代码示例1
import { useState, useEffect, useRef } from "react";
import { Chart as ChartJS, ArcElement, Tooltip, Legend } from "chart.js";
import { Pie } from "react-chartjs-2";

ChartJS.register(ArcElement, Tooltip, Legend);

export const data = {
  labels: ["Case on Hold", "Submitted", "In Production", "Shipped"],
  datasets: [
    {
      label: "# of Votes",
      data: [12, 19, 3, 5],
      backgroundColor: ["#F2CC59", "#BA68C8", "#407BFF", "#E6E5E6"],
      borderColor: ["#F2CC59", "#BA68C8", "#407BFF", "#E6E5E6"],
      borderWidth: 1,
    },
  ],
};

const pieOptions = {
  plugins: {
    legend: {
      display: false,
      labels: {
        font: {
          size: 12,
        },
      },
    },
  },
};

export default function ChartView() {
  const [charView, setChatView] = useState([]);
  const summaryRef: any = useRef(null);

  useEffect(() => {
    setChatView(summaryRef?.current?.legend?.legendItems);
  }, []);

  return (
    
{charView?.map((data: any, i: number) => ( {data?.text} ))}
); }