결과

내용
- Import 버큰클릭시 브라우저 기본 파일 탐색기 호출
- 지정한 "chart.json" 파일 첨부
- json 파일 파싱, 그래프 생성
코드
import Highcharts from 'highcharts';
const [upload, setUpload] = useState(false);
const [data, setData] = useState([]);
useEffect(() => {
fetch('data/Chart.json')
.then(res => res.json())
.then(data => {
setData(data.res);
});
}, []);
useEffect(() => {
async function chartRequest() {
const chart = await Highcharts.chart('request', {
chart: {
type: 'line',
},
title: {
text: '',
},
yAxis: {
title: '',
},
yAxis: {
title: {
text: '',
},
},
credits: {
enabled: false,
},
series: [
{
name: '',
data: data[0].data,
},
],
});
}
chartRequest();
}, [!upload]);
useEffect(() => {
async function chartTotal() {
const chart = await Highcharts.chart('request_total', {
chart: {
type: 'line',
},
title: {
text: '',
},
yAxis: {
title: '',
},
yAxis: {
title: {
text: '',
},
},
credits: {
enabled: false,
},
series: [
{
name: '',
data: data[1].data,
},
],
});
}
chartTotal();
}, [upload]);
const handleCheck = e => {
const values = e.target.value.includes('chart.json');
if (values) setUpload(!upload);
};
return (
<Main>
<Title titleText="Chart" />
<TwoButton buttonTextFirst="Import" handleCheck={handleCheck} />
{upload && (
<BasicChart
data={data}
request="request"
request_total="request_total"
/>
)}
</Main>
);
};