From 0c9f76d73acf8c8eceebf69e72abece9956775e8 Mon Sep 17 00:00:00 2001 From: novice1993 Date: Tue, 19 Sep 2023 02:35:53 +0900 Subject: [PATCH] =?UTF-8?q?[Feat]=20=EB=B9=84=EA=B5=90=EC=B0=A8=ED=8A=B8?= =?UTF-8?q?=20=EC=A2=85=EB=AA=A9=EB=AA=85=20=EB=A0=8C=EB=8D=94=EB=A7=81=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 비교차트 종목명이 함께 렌더링 되도록 기능 추가 Issues #14 --- client/src/hooks/useGetStockChart.tsx | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/client/src/hooks/useGetStockChart.tsx b/client/src/hooks/useGetStockChart.tsx index 6aef5f7..9864e8e 100644 --- a/client/src/hooks/useGetStockChart.tsx +++ b/client/src/hooks/useGetStockChart.tsx @@ -19,20 +19,22 @@ const useGetStockChart = (companyId: number) => { const [corpName, setCorpName] = useState(""); // 비교차트 설정 (10일 기준, 이동 평균선) + const [compareName, setCompareName] = useState(""); const [compareChart, setCompare] = useState(undefined); const compareId = useSelector((state: StateProps) => state.compareChart); + const { stockInfo: compareInfo } = useGetStockInfo(compareId); const url = "http://ec2-13-125-246-160.ap-northeast-2.compute.amazonaws.com:8080/companies/charts/"; const averageDay = 10; - const getCompareChart = async (compareId: number) => { + const getCompareChart = async (compareId: number, compareName: strign) => { const response = await axios.get(`${url}${compareId}`); const data = await response.data; const compareChartData = organizeData(data); const compareMovingAvgData = calculateMovingAvgLine(averageDay, compareChartData); const compareMovingAvgChart = { - name: "비교차트", + name: `${compareName}`, type: "line", data: compareMovingAvgData, smooth: true, @@ -46,15 +48,23 @@ const useGetStockChart = (companyId: number) => { setCompare(compareMovingAvgChart); }; + useEffect(() => { + if (compareInfo && compareId !== null) { + const compareStockName = compareInfo.korName; + console.log(compareStockName); + setCompareName(compareStockName); + } + }, [compareInfo]); + useEffect(() => { if (compareId !== null) { - getCompareChart(compareId); + getCompareChart(compareId, compareName); } if (companyId === null) { setCompare(undefined); } - }, [compareId]); + }, [compareId, compareName]); useEffect(() => { if (stockPrice && stockInfo) { @@ -72,7 +82,7 @@ const useGetStockChart = (companyId: number) => { top: 10, left: "left", padding: [4, 0, 0, 15], - data: [`주가`, `거래량`, `이동평균선 (${averageLineMinute}분)`, compareChart !== undefined && "비교차트"], + data: [`주가`, `거래량`, `이동평균선 (${averageLineMinute}분)`, compareChart !== undefined && `${compareName}`], }, tooltip: { trigger: "axis",