"use client"; import React from "react"; import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from "recharts"; import { ChartConfig } from "../types"; interface StackedBarChartComponentProps { data: any[]; config: ChartConfig; width?: number; height?: number; } /** * 누적 바 차트 컴포넌트 * - Recharts BarChart (stacked) 사용 * - 전체 대비 비율 파악에 적합 * - 다중 시리즈를 누적으로 표시 */ export function StackedBarChartComponent({ data, config, width = 250, height = 200 }: StackedBarChartComponentProps) { const { xAxis = "x", yAxis = "y", colors = ["#3B82F6", "#EF4444", "#10B981", "#F59E0B"], title, showLegend = true, } = config; // Y축 필드들 (단일 또는 다중) const yFields = Array.isArray(yAxis) ? yAxis : [yAxis]; const yKeys = yFields.filter((field) => field && field !== "y"); return (
{title &&
{title}
} [typeof value === "number" ? value.toLocaleString() : value, name]} /> {showLegend && } {yKeys.map((key, index) => ( ))}
); }