kcscDev/egovframe-template-simple-r.../src/pages/admin/schedule/MonthlyBarChart.jsx

125 lines
3.0 KiB
React
Raw Normal View History

2024-02-07 09:52:29 +00:00
import {useCallback, useEffect, useState} from 'react';
2024-01-31 07:37:36 +00:00
// material-ui
import { useTheme } from '@mui/material/styles';
// third-party
import ReactApexChart from 'react-apexcharts';
2024-02-07 09:52:29 +00:00
import * as EgovNet from 'api/egovFetch';
2024-01-31 07:37:36 +00:00
// chart options
const barChartOptions = {
chart: {
type: 'bar',
height: 365,
toolbar: {
show: false
}
},
plotOptions: {
bar: {
columnWidth: '45%',
borderRadius: 4
}
},
dataLabels: {
2024-02-07 09:52:29 +00:00
enabled: true
2024-01-31 07:37:36 +00:00
},
xaxis: {
categories: ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'],
axisBorder: {
show: false
},
axisTicks: {
show: false
}
},
yaxis: {
show: false
},
grid: {
show: false
}
};
// ==============================|| MONTHLY BAR CHART ||============================== //
2024-02-07 09:52:29 +00:00
const MonthlyBarChart = ({ onDataFetched }) => {
2024-01-31 07:37:36 +00:00
const theme = useTheme();
const { primary, secondary } = theme.palette.text;
const info = theme.palette.info.light;
2024-02-07 09:52:29 +00:00
const [options, setOptions] = useState(barChartOptions);
const [fileDailyList, setFileDailyList] = useState([]);
// 메뉴 접속 및 방문자 수
const retrieveList = useCallback(() => {
const retrieveListURL = '/admin/dashboard/file'
const requestOptions = {
method: "POST",
headers: {
'Content-type': 'application/json',
},
// body: JSON.stringify()
}
EgovNet.requestFetch(retrieveListURL,
requestOptions,
(resp) => {
setFileDailyList(resp.result.fileDailyList);
const sum = resp.result.fileDailyList.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
onDataFetched(sum);
},
function (resp) {
console.log("err response : ", resp);
}
);
// eslint-disable-next-lie react-hooks/exhaustive-deps
}, []);
const [series, setSeries] = useState([
2024-01-31 07:37:36 +00:00
{
2024-02-07 10:02:07 +00:00
name: '다운로드수',
2024-02-07 09:52:29 +00:00
data: fileDailyList
2024-01-31 07:37:36 +00:00
}
]);
2024-02-07 09:52:29 +00:00
useEffect(() => {
retrieveList();
}, [onDataFetched]);
2024-01-31 07:37:36 +00:00
useEffect(() => {
2024-02-07 09:52:29 +00:00
setSeries([
{
data: fileDailyList
},
]);
2024-01-31 07:37:36 +00:00
setOptions((prevState) => ({
...prevState,
colors: [info],
xaxis: {
labels: {
style: {
2024-02-07 10:02:07 +00:00
colors: [secondary, secondary, secondary, secondary, secondary, secondary, secondary]
2024-01-31 07:37:36 +00:00
}
}
},
tooltip: {
theme: 'light'
2024-02-07 09:52:29 +00:00
},
2024-01-31 07:37:36 +00:00
}));
// eslint-disable-next-line react-hooks/exhaustive-deps
2024-02-07 09:52:29 +00:00
}, [primary, info, secondary, fileDailyList]);
2024-01-31 07:37:36 +00:00
return (
<div id="chart">
<ReactApexChart options={options} series={series} type="bar" height={365} />
</div>
);
};
export default MonthlyBarChart;