Price Chart part Three
apexcart options 이용해 디자인 보완
Chart.tsx
import { useQuery } from 'react-query';
import { fetchCoinHistory } from './api';
import ApexChart from 'react-apexcharts';
interface IHistorycal {
time_open: string;
time_close: string;
open: number;
high: number;
low: number;
close: number;
volume: number;
market_cap: number;
}
interface ChartProps {
coinId: string;
}
function Chart({ coinId }: ChartProps) {
const { isLoading, data } = useQuery<IHistorycal[]>(['ohlcv', coinId], () =>
fetchCoinHistory(coinId)
);
return (
<div>
{isLoading ? (
'Loading chart...'
) : (
<ApexChart
type="line"
series={[
{
name: 'price',
data: data?.map((price) => price.close) as number[],
},
]}
options={{
theme: { mode: 'dark' },
chart: {
width: 500,
height: 300,
toolbar: { show: false },
background: 'transparents',
},
grid: { show: false },
stroke: { curve: 'smooth', width: 3 },
yaxis: { show: false },
xaxis: {
labels: { show: false },
axisTicks: { show: false },
axisBorder: { show: false },
type: 'datetime',
categories: data?.map((price) => price.time_close),
},
fill: {
type: 'gradient',
gradient: { gradientToColors: ['#0be881'], stops: [0, 100] },
},
colors: ['blue'],
tooltip: { y: { formatter: (value) => `$ ${value.toFixed(3)}` } },
}}
/>
)}
</div>
);
}
export default Chart;