Files
hats-app/app/admin/administration/user/component/EmployeePerformance/AreaChart.tsx
T
2025-12-19 13:57:55 +07:00

156 lines
5.0 KiB
TypeScript

'use client'
import { FC } from 'react';
import Chart from 'react-apexcharts';
import { type ApexOptions } from 'apexcharts';
import { useTheme } from 'next-themes';
import useMobileView from '@/hooks/useMobileView';
import { getArrayRandomNumber, getLastNDays } from '@/lib/helper';
type Props = {
data: any
};
const AreaChart: FC<Props> = ({ data }) => {
const { theme, systemTheme } = useTheme()
const { windowWidth } = useMobileView()
const options: ApexOptions = {
chart: {
type: 'area',
fontFamily: 'Inter, Arial, sans-serif',
toolbar: {
show: false
},
offsetX: windowWidth < 400 ? 430 : windowWidth < 600 ? 390 : 0
},
colors: ['#f43f5e', '#22c55e'],
legend: {
position: 'top',
show: true,
fontSize: '16px',
labels: {
colors: theme === 'dark' ? '#fff' : theme === 'system' && systemTheme === 'dark' ? '#fff' : '#000',
useSeriesColors: false
},
},
dataLabels: {
enabled: false,
},
stroke: {
show: true,
curve: 'smooth',
width: 2,
},
xaxis: {
type: 'datetime',
categories: getLastNDays(30),
labels: {
show: true,
rotateAlways: true,
minHeight: 40,
maxHeight: 40,
format: 'dd/MM',
style: {
colors: theme === 'dark' ? '#a1a1aa' : theme === 'system' && systemTheme === 'dark' ? '#a1a1aa' : '#71717a',
fontSize: '14px',
}
}
},
yaxis: {
// tickAmount: 24,
min: 0,
max: 24,
labels: {
formatter: (val) => val.toFixed(0),
style: {
colors: theme === 'dark' ? '#a1a1aa' : theme === 'system' && systemTheme === 'dark' ? '#a1a1aa' : '#71717a',
fontSize: '14px',
}
}
},
grid: {
yaxis: {
lines: { show: false }
},
padding: {
right: 25 // Also you may want to increase this (based on the length of your labels)
},
},
fill: {
type: 'gradient',
gradient: {
shadeIntensity: 1,
inverseColors: false,
opacityFrom: 0.5,
opacityTo: 0.1,
stops: [20, 100, 100, 100]
},
},
tooltip: {
theme: theme === 'dark' ? 'dark' : theme === 'system' && systemTheme === 'dark' ? 'dark' : 'light',
style: { fontSize: '14px' },
x: {
format: 'MMM dd, yyyy'
},
y: {
formatter: (val) => val.toFixed(2)
}
},
responsive: [{
breakpoint: 800,
options: {
legend: { fontSize: '14px' },
yaxis: {
min: 0,
max: 24,
labels: {
formatter: (val: any) => val.toFixed(0),
style: {
colors: theme === 'dark' ? '#a1a1aa' : theme === 'system' && systemTheme === 'dark' ? '#a1a1aa' : '#71717a',
fontSize: '12px',
}
}
},
xaxis: {
labels: {
rotateAlways: true,
minHeight: 35,
maxHeight: 35,
style: {
colors: theme === 'dark' ? '#a1a1aa' : theme === 'system' && systemTheme === 'dark' ? '#a1a1aa' : '#71717a',
fontSize: '12px',
}
}
},
},
}]
}
const series = [
{
name: 'Check-Out',
data: getArrayRandomNumber(30, 17, 24)
},
{
name: 'Check-In',
data: getArrayRandomNumber(30, 8, 11)
}
]
return (
<>
{/* <div className='h-[400px] 2xl:h-[500px] flex items-center justify-center -mt-3 overflow-hidden overflow-x-auto max-w-[300px] sm:max-w-full'> */}
<div className='h-[400px] 2xl:h-[500px] flex items-center justify-center -mt-3 overflow-hidden overflow-x-auto' style={{ maxWidth: windowWidth > 760 ? '100%' : windowWidth > 400 ? 400 : 310 }}>
<Chart
type='area'
options={options}
series={series}
width={windowWidth > 1900 ? '450%' : windowWidth > 1500 ? '420%' : windowWidth > 1280 ? '405%' : windowWidth > 760 ? 640 : '390%'}
height='100%'
/>
</div>
</>
);
}
export default AreaChart;