From 31b8152d37b8fbfb40e92a7829976c954102966c Mon Sep 17 00:00:00 2001 From: jsyang Date: Wed, 27 Aug 2025 14:56:02 +0900 Subject: [PATCH] =?UTF-8?q?=EC=B0=A8=ED=8A=B8=20=EC=A2=8C=EC=9A=B0=20axis?= =?UTF-8?q?=20custom=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/ui/chart/LineBarChart.tsx | 48 ++++++++++++++++--- .../src/ui/chart/LineChart.tsx | 36 +++++++++++++- 2 files changed, 77 insertions(+), 7 deletions(-) diff --git a/packages/common/business_components/src/ui/chart/LineBarChart.tsx b/packages/common/business_components/src/ui/chart/LineBarChart.tsx index 9f9a4feec..2a2ba2b1c 100644 --- a/packages/common/business_components/src/ui/chart/LineBarChart.tsx +++ b/packages/common/business_components/src/ui/chart/LineBarChart.tsx @@ -7,6 +7,7 @@ import { } from "./lib/chart"; import type { ContentType } from "recharts/types/component/DefaultLegendContent"; import type { set } from "date-fns"; +import React from "react"; // 툴크 커스텀 css /** 차트 기본 스타일 */ @@ -126,6 +127,37 @@ export default function LineBarchart({ monthTicks = getTicks(chartData); } + const CustomAxisText : React.FC<{ viewBox: any, fieldText: string, position:string }> = ({ viewBox, fieldText, position }) => { + const { x, y, width, height } = viewBox; // 축 영역 + const padding = 5; // 차트 바깥으로 띄우기 + + if('left' == position) { + return ( + + {fieldText} + + ); + }else{ + return ( + + {fieldText} + + ); + } + } + return (
{chartTitle && chartTitle !== "" && chartTitle !== "undefined" ? ( @@ -151,18 +183,22 @@ export default function LineBarchart({ yAxisId="left" className="text-[12px] font-bold" tickCount={6} - orientation="left" - domain={[0, Math.ceil(lineMaxValue * 1)]} - label={{ value: yFieldText, angle: -90, position: 'insideLeft', offset: -8 }} + tickFormatter={(value) => + typeof value === "number" ? value.toLocaleString() : value + } + orientation="left" + label={(props) => } />} {/* 오른쪽 Y축: barVal */} {yFieldText2 && + typeof value === "number" ? value.toLocaleString() : value + } + label={(props) => } reversed={true} />} } /> diff --git a/packages/common/business_components/src/ui/chart/LineChart.tsx b/packages/common/business_components/src/ui/chart/LineChart.tsx index a76807bae..314a0b240 100644 --- a/packages/common/business_components/src/ui/chart/LineChart.tsx +++ b/packages/common/business_components/src/ui/chart/LineChart.tsx @@ -129,6 +129,37 @@ const CustomLegend = (props: LegendProps) => { ); }; +const CustomAxisText : React.FC<{ viewBox: any, fieldText: string, position:string }> = ({ viewBox, fieldText, position }) => { + const { x, y, width, height } = viewBox; // 축 영역 + const padding = 5; // 차트 바깥으로 띄우기 + + if('left' == position) { + return ( + + {fieldText} + + ); + }else{ + return ( + + {fieldText} + + ); + } +} + type DataType = {label: string; val: string}; type ChartDataType = { @@ -220,7 +251,10 @@ export default function Linechart({ yAxisId="left" className="text-[12px] font-bold" orientation="left" - label={{ value: yFieldText, className:"text-[12px] font-bold", angle: -90, position: 'insideLeft' }} /> + tickFormatter={(value) => + typeof value === "number" ? value.toLocaleString() : value + } + label={(props) => }/> } /> {showLegend && } {Object.keys(chartData).map((key) => {