mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:46:29 +00:00
169 lines
4.9 KiB
TypeScript
169 lines
4.9 KiB
TypeScript
'use client'
|
|
|
|
import { FC } from 'react';
|
|
import { type ApexOptions } from 'apexcharts';
|
|
import { useTheme } from 'next-themes';
|
|
import useMobileView from '@/hooks/useMobileView';
|
|
import dynamic from 'next/dynamic';
|
|
import LazyLoading from '@/components/loader/LazyLoading';
|
|
|
|
const ReactApexChart = dynamic(() => import('react-apexcharts'), {
|
|
loading: () => <LazyLoading />,
|
|
ssr: false
|
|
});
|
|
|
|
type Props = {
|
|
data: any
|
|
};
|
|
|
|
const AreaChart: FC<Props> = ({ data }) => {
|
|
const { theme, systemTheme } = useTheme()
|
|
const { isMobile } = useMobileView()
|
|
|
|
// console.log(data)
|
|
|
|
const options: ApexOptions = {
|
|
chart: {
|
|
type: 'area',
|
|
fontFamily: 'Inter, Arial, sans-serif',
|
|
toolbar: {
|
|
show: false
|
|
},
|
|
},
|
|
colors: ['#f43f5e', '#22c55e', '#8b5cf6', '#eab308', '#06b6d4'],
|
|
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: data.list_date.slice(-14),
|
|
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: {
|
|
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: 30 // 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: data.report[1].name,
|
|
// data: data.report[1].data.slice(-7)
|
|
// },
|
|
// {
|
|
// name: data.report[0].name,
|
|
// data: data.report[0].data.slice(-7)
|
|
// }
|
|
// ]
|
|
|
|
const series = () => {
|
|
return data.report.map((item: any) => {
|
|
return {
|
|
name: item.name,
|
|
data: item.data.slice(-14)
|
|
}
|
|
})
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<div className='h-[300px] sm:h-[400px] flex items-center justify-center w-full -mt-3'>
|
|
<ReactApexChart
|
|
type='area'
|
|
options={options}
|
|
series={series()}
|
|
width={isMobile ? 350 : '200%'}
|
|
height='100%'
|
|
/>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|
|
|
|
export default AreaChart; |