'use client'; import { ChartData } from '@/types/chart'; import { Cell, Legend, Pie, PieChart, ResponsiveContainer, Tooltip, } from 'recharts'; type ChartPieProps = { loading: boolean data: ChartData[] } export function ChartPie({ loading, data }: ChartPieProps) { const items = 5; // Calculate percentages const dataWithPercentages = data ? (() => { const total = data.reduce((sum, item) => sum + item.value, 0); return data.map(item => ({ ...item, percentage: total > 0 ? Number(((item.value / total) * 100).toFixed(1)) : 0 })); })() : []; const total = dataWithPercentages.reduce((sum, item) => sum + item.value, 0); if (loading) { return (
No data available
Total
{total}