-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 서버에서 데이터 패칭 후 차트 그리는 기본 로직 구현 - 최초 렌더링 이후 정각 혹은 30분 마다 API 호출하여 데이터 갱신되도록 로직 구현 - 현재 단일 주식 로직만 구현된 상황으로, 추후 로직 확장 예정 Issues #14
- Loading branch information
1 parent
c459e64
commit 8f6a761
Showing
7 changed files
with
247 additions
and
69 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { useState, useEffect } from "react"; | ||
import useGetStockData from "./useGetStockData"; | ||
|
||
const useGetChart = () => { | ||
const { data } = useGetStockData(); | ||
const [chartData, setChartData] = useState([]); | ||
|
||
useEffect(() => { | ||
if (data) { | ||
setChartData(data); | ||
} | ||
}, [data]); | ||
|
||
const options = { | ||
xAxis: { | ||
type: "category", | ||
data: chartData.map((stock: StockProps) => { | ||
const date = new Date(stock.stockTradeTime); | ||
const tradeTime = `${date.getHours()}:${date.getMinutes()}`; | ||
return tradeTime; | ||
}), | ||
}, | ||
yAxis: [ | ||
{ | ||
type: "value", | ||
position: "right", | ||
interval: 100, | ||
min: 70000, | ||
}, | ||
], | ||
dataZoom: [ | ||
{ | ||
type: "inside", | ||
}, | ||
], | ||
tooltip: { | ||
trigger: "axis", | ||
axisPointer: { | ||
type: "cross", | ||
}, | ||
}, | ||
series: [ | ||
{ | ||
name: "주가", | ||
type: "candlestick", | ||
data: chartData.map((stock: StockProps) => { | ||
return [stock.stck_oprc, stock.stck_prpr, stock.stck_lwpr, stock.stck_hgpr]; | ||
}), | ||
yAxisIndex: 0, | ||
}, | ||
], | ||
}; | ||
|
||
const chartStyle = { | ||
width: "100%", | ||
height: "100%", | ||
}; | ||
|
||
return { options, chartStyle }; | ||
}; | ||
|
||
export default useGetChart; | ||
|
||
interface StockProps { | ||
stockMinId: number; | ||
companyId: number; | ||
stockTradeTime: string; | ||
stck_cntg_hour: string; | ||
stck_prpr: string; | ||
stck_oprc: string; | ||
stck_hgpr: string; | ||
stck_lwpr: string; | ||
} |
Oops, something went wrong.