import { PieChart, Pie, Cell, ResponsiveContainer, Legend, Tooltip, } from "recharts"; interface SentimentData { name: string; value: number; color: string; } interface SentimentChartProps { data: SentimentData[]; } export function SentimentChart({ data }: SentimentChartProps) { const total = data.reduce((sum, item) => sum + item.value, 0); const CustomTooltip = ({ active, payload }: any) => { if (active && payload && payload.length) { const item = payload[0].payload; const percentage = ((item.value / total) * 100).toFixed(1); return (

{item.name}

{item.value.toLocaleString()} ulasan ({percentage}%)

); } return null; }; const renderCustomLabel = ({ cx, cy, midAngle, innerRadius, outerRadius, percent, }: any) => { if (percent < 0.05) return null; const RADIAN = Math.PI / 180; const radius = innerRadius + (outerRadius - innerRadius) * 0.5; const x = cx + radius * Math.cos(-midAngle * RADIAN); const y = cy + radius * Math.sin(-midAngle * RADIAN); return ( {`${(percent * 100).toFixed(0)}%`} ); }; return (
{data.map((entry, index) => ( ))} } /> ( {value} )} />
); }