'use client' import { FC } from 'react'; import { type ApexOptions } from 'apexcharts'; import { useTheme } from 'next-themes'; import useMobileView from '@/hooks/useMobileView'; import dayjs from 'dayjs'; import dynamic from 'next/dynamic'; import LazyLoading from '@/components/loader/LazyLoading'; const Chart = dynamic(() => import('react-apexcharts'), { loading: () => , ssr: false }); type Props = { data: any }; const AreaChart: FC = ({ 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', '#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: { tickAmount: windowWidth >= 1024 ? 60 : windowWidth >= 768 ? 45 : windowWidth >= 480 ? 30 : 15, type: 'category', categories: data.list_date, labels: { show: true, rotateAlways: true, minHeight: 40, maxHeight: 40, formatter: (val) => dayjs(val).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) // } // ] const series = () => { return data.report.map((item: any) => { return { name: item.name, data: item.data } }) } return ( <>
1900 ? '445%' : windowWidth > 1280 ? '425%' : windowWidth >= 760 ? '240%' : windowWidth >= 480 ? '150%' : '120%'} height='100%' />
); } export default AreaChart;