-
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.
Merge pull request #52 from codestates-seb/dev-client#14/chartGraph
[FE] #14 차트 관련 통신로직 일부 구현
- Loading branch information
Showing
7 changed files
with
267 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,75 @@ | ||
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.stck_cntg_hour); | ||
const hours = stock.stck_cntg_hour.substring(0, 2); | ||
const minutes = stock.stck_cntg_hour.substring(2, 4); | ||
const tradeTime = `${hours}:${minutes}`; | ||
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.