import { Chart } from "react-chartjs-2"; import { Chart as ChartJS, CategoryScale, LinearScale, BarController, BarElement, LineController, LineElement, PointElement, Title, Tooltip, Legend, } from "chart.js"; import type { ChartOptions } from "chart.js"; ChartJS.register( CategoryScale, LinearScale, BarController, BarElement, LineController, LineElement, PointElement, Title, Tooltip, Legend, ); // 차트 설정 외부 정의 (Mixed 타입 명시) const options: ChartOptions<"bar" | "line"> = { responsive: true, maintainAspectRatio: false, scales: { x: { stacked: true }, y: { stacked: true, beginAtZero: true, title: { display: true, text: "인구수(명)" }, }, y1: { position: "right", beginAtZero: true, grid: { drawOnChartArea: false }, title: { display: true, text: "총 인구(명)" }, }, }, plugins: { legend: { position: "bottom" }, }, }; export type PopulationChartData = { X_AXIS: string[]; TOT: number[]; ORIGIN_MALE: (number | null)[]; ORIGIN_FEMALE: (number | null)[]; FOREIGN_MALE: (number | null)[]; FOREIGN_FEMALE: (number | null)[]; }; type Props = { chartData: PopulationChartData | null; }; const SERIES_META = [ { key: "ORIGIN_MALE", name: "내국인 남성", color: "#3B82F6" }, { key: "ORIGIN_FEMALE", name: "내국인 여성", color: "#EC4899" }, { key: "FOREIGN_MALE", name: "외국인 남성", color: "#10B981" }, { key: "FOREIGN_FEMALE", name: "외국인 여성", color: "#F59E0B" }, ] as const; const PopulationStatusChart = ({ chartData }: Props) => { if (!chartData || chartData.X_AXIS.length === 0) { return (