도넛바 차트 에러 수정

This commit is contained in:
YangJinSoo94
2025-07-14 14:25:31 +09:00
parent ed7a56480e
commit a23b80431c
@@ -6,22 +6,13 @@ import {
Card, Card,
CardContent CardContent
} from "./lib/card"; } from "./lib/card";
import { ChartContainer, ChartTooltip } from "./lib/chart"; import { ChartContainer, ChartTooltip, type ChartConfig } from "./lib/chart";
type ChartDataItem = { type ChartDataItem = {
label: string; label: string;
val: number; val: number;
}; };
type ChartConfigItem = {
label: string;
fill: string;
};
type ChartConfig = {
[key: string]: ChartConfigItem;
};
type TooltipPayloadItem = { type TooltipPayloadItem = {
name: string; name: string;
value: number; value: number;
@@ -47,20 +38,6 @@ type LegendProps = {
payload?: LegendEntry[]; payload?: LegendEntry[];
}; };
/** 차트 기본 스타일 */
/*
const customStyles = {
legendContainer: {
display: "flex",
justifyContent: "center",
gap: "20px",
fontSize: "9px",
fontWeight: "bold",
marginTop: "10px",
} as CSSProperties,
};
*/
/** 차트 기본 스타일 (라인차트와 동일하게) */ /** 차트 기본 스타일 (라인차트와 동일하게) */
const customStyles = { const customStyles = {
legendContainer: { legendContainer: {
@@ -99,25 +76,6 @@ const CustomTooltip = ({ active, payload, label }: {
return null; return null;
}; };
// 커스텀 범례
/*
const CustomLegend = (props: LegendProps) => {
const { payload } = props;
if (!payload) return null;
return (
<div style={customStyles.legendContainer}>
{payload.map((entry: LegendEntry, index: number) => (
<div key={`legend-${index}`} className="flex items-center gap-2">
<div className="w-[14px] h-[14px] ml-10" style={{ backgroundColor: entry.fill }}></div>
<span className="text-[12px]">{entry.value}</span>
</div>
))}
</div>
);
};
*/
const CustomLegend = (props: LegendProps) => { const CustomLegend = (props: LegendProps) => {
const { payload } = props; const { payload } = props;
if (!payload) return null; if (!payload) return null;
@@ -154,14 +112,20 @@ const CustomLegend = (props: LegendProps) => {
}; };
export default function DoughnutChart(props: { export default function DoughnutChart(props: {
chartConfig: any; chartConfig: ChartConfig;
chartData: ChartDataItem[] | undefined; chartData: ChartDataItem[] | undefined;
chartTitle: string chartTitle: string
}) { }) {
const legendData = props.chartData?.map(item => ({ const legendData = props.chartData?.map(item => ({
value: item.label, value: item.label,
fill: props.chartConfig?.[item.label]?.fill || 'blue', fill: props.chartConfig?.[item.label]?.color || 'blue',
payload: {
label: item.label,
val: item.val,
fill: props.chartConfig?.[item.label]?.color || 'blue'
}
})) ?? []; })) ?? [];
return ( return (
<Card className="flex flex-col"> <Card className="flex flex-col">
<CardContent className="flex-1 pb-0"> <CardContent className="flex-1 pb-0">
@@ -183,7 +147,7 @@ export default function DoughnutChart(props: {
<Pie <Pie
data={props.chartData?.map(item => ({ data={props.chartData?.map(item => ({
...item, ...item,
fill: props.chartConfig[item.label]?.fill || 'blue' fill: props.chartConfig[item.label]?.color || 'blue'
}))} }))}
dataKey="val" dataKey="val"
nameKey="label" nameKey="label"