import * as Plot from "@observablehq/plot"; import { Card } from "react-bootstrap"; import React, {useRef, useEffect} from "react"; const PieChartComponent = ({ tasks }) => { const chartRef = useRef(); useEffect(() => { if (chartRef.current) { while (chartRef.current.firstChild) { chartRef.current.removeChild(chartRef.current.firstChild); } const priorityCounts = tasks.reduce((acc, task) => { acc[task.priority] = (acc[task.priority] || 0) + 1; return acc; }, {}); const data = Object.entries(priorityCounts).map(([priority, count]) => ({ priority, count })); const chart = Plot.plot({ marks: [ Plot.barY(data, { x: "priority", y: "count", fill: "priority", stroke: "white", title: d => `${d.priority}: ${d.count}`, r: "count" }) ], height: 500, width: 600, }); chartRef.current.append(chart); } }, [tasks]); return ( Task Priority Distribution
); }; export default PieChartComponent;