'use client'; import React from 'react'; import { PieChart, Pie, Cell, Tooltip, Legend, ResponsiveContainer } from 'recharts'; import { ChartConfig } from '../types'; interface DonutChartComponentProps { data: any[]; config: ChartConfig; width?: number; height?: number; } /** * 도넛 차트 컴포넌트 * - Recharts PieChart (innerRadius 사용) 사용 * - 비율 표시에 적합 (중앙 공간 활용 가능) */ export function DonutChartComponent({ data, config, width = 250, height = 200 }: DonutChartComponentProps) { const { xAxis = 'x', yAxis = 'y', colors = ['#3B82F6', '#EF4444', '#10B981', '#F59E0B', '#8B5CF6', '#EC4899'], title, showLegend = true } = config; // 파이 차트용 데이터 변환 const pieData = data.map(item => ({ name: String(item[xAxis] || ''), value: typeof item[yAxis as string] === 'number' ? item[yAxis as string] : 0 })); // 총합 계산 const total = pieData.reduce((sum, item) => sum + item.value, 0); // 커스텀 라벨 (퍼센트 표시) const renderLabel = (entry: any) => { const percent = ((entry.value / total) * 100).toFixed(1); return `${percent}%`; }; return (