'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 (
{Array.from({ length: items }).map((_, index) => (
))}
); } if (!data || data.length === 0) { return (

No data available

); } return (
{/* Total Count */}

Total

{total}

`${percentage}%`} > {dataWithPercentages.map((entry, index) => ( ))} [ `${value} (${props.payload.percentage}%)`, name ]} /> `${value}: ${entry.payload.value} (${entry.payload.percentage}%)` } />
); }