From aeaf507c47713787e7a476560c08a409c601bf8f Mon Sep 17 00:00:00 2001 From: jsyang Date: Tue, 26 Aug 2025 17:39:07 +0900 Subject: [PATCH] =?UTF-8?q?=EC=B0=A8=ED=8A=B8property=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=20(setXAxisYearTick=20-=20=EB=82=A0=EC=A7=9C=20x=EC=B6=95?= =?UTF-8?q?=EC=9D=BC=EA=B2=BD=EC=9A=B0=20(=EB=85=84=EB=8F=84-=EC=9B=94)?= =?UTF-8?q?=EB=B3=84=EB=A1=9C=20=EB=A7=8C=EB=93=A4=EC=96=B4=EC=A3=BC?= =?UTF-8?q?=EB=8A=94=20=EC=86=8D=EC=84=B1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/ui/chart/LineChart.tsx | 58 ++++++++++++++----- .../src/ui/chart/index.tsx | 3 +- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/packages/common/business_components/src/ui/chart/LineChart.tsx b/packages/common/business_components/src/ui/chart/LineChart.tsx index 23570912d..63851cbea 100644 --- a/packages/common/business_components/src/ui/chart/LineChart.tsx +++ b/packages/common/business_components/src/ui/chart/LineChart.tsx @@ -6,6 +6,7 @@ import { ChartContainer, type ChartConfig } from "./lib/chart"; +import { get } from "http"; type LineChartProps = { chartConfig: ChartConfig | undefined; @@ -15,6 +16,7 @@ type LineChartProps = { graphSize?: number; yFieldText?: string; showLegend?: boolean; + setXAxisYearTick?: boolean; } /** 차트 기본 스타일 */ @@ -141,7 +143,8 @@ export default function Linechart({ chartClassName = 'w-full h-full', graphSize = 40, yFieldText, - showLegend = true + showLegend = true, + setXAxisYearTick = false, }: LineChartProps) { if (!chartData || Object.keys(chartData).length === 0) { return
데이터가 없습니다.
; @@ -164,18 +167,24 @@ export default function Linechart({ return acc; }, []); - // 데이터의 최대값 계산 - const getMaxValue = (data: ChartDataType): number => { - return Math.max(...Object.values(data).flatMap(dataset => - dataset.map(entry => { - const val = parseFloat(entry.val); - return isNaN(val) ? 0 : val; - }) - )); - }; - - const lineMaxValue = getMaxValue(chartData); - + const getTicks = (data : any []) => { + const monthSet = new Set(); + const rtnData : string[] = []; + for(const item of data){ + const month = String(item.label).slice(0,7); + if(!monthSet.has(month)){ + monthSet.add(month); + rtnData.push(item.label); + } + } + return rtnData; + } + + let monthTicks : string[] = []; + if(setXAxisYearTick){ + monthTicks = getTicks(mergedData); + } + return (
{chartTitle && chartTitle !== "" && chartTitle !== "undefined" ? ( @@ -192,8 +201,27 @@ export default function Linechart({ margin={{ top: 5, right: 30, left: 20, bottom: 5 }} > - - value.toLocaleString()} tickCount={6} orientation="left" label={{ value: yFieldText, className:"text-[12px] font-bold", angle: -90, position: 'insideLeft' }} /> + + {setXAxisYearTick ? + value.slice(0,7)} + /> : + + } + + } /> {showLegend && } {Object.keys(chartData).map((key) => { diff --git a/packages/common/business_components/src/ui/chart/index.tsx b/packages/common/business_components/src/ui/chart/index.tsx index ee308e378..a6e1ff245 100644 --- a/packages/common/business_components/src/ui/chart/index.tsx +++ b/packages/common/business_components/src/ui/chart/index.tsx @@ -56,6 +56,7 @@ type MainChartProps = { yFieldText? : string | undefined; yFieldText2? : string | undefined; showLegend? : boolean; + setXAxisYearTick ?: boolean; } function MainChart(props: MainChartProps) { @@ -65,7 +66,7 @@ function MainChart(props: MainChartProps) { ); } else if( props.chartForm == CHART_FORM.LINE ){ return ( - + ); } else if( props.chartForm == CHART_FORM.DN ){ return (