mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:46:29 +00:00
a160eccddf
Adjust chart components (Overview, PieChart) for sizing and safer typings/casting; add v1.2.0 release note. Remove several obsolete dummy/old task pages and the useDummyTaskData hook. Also include minor fixes to FormClient and DonutChart/performance pages.
107 lines
3.0 KiB
TypeScript
107 lines
3.0 KiB
TypeScript
'use client'
|
|
|
|
import { FC } from 'react';
|
|
import { type ApexOptions } from 'apexcharts';
|
|
import { useTheme } from 'next-themes';
|
|
import dynamic from 'next/dynamic';
|
|
import LazyLoading from '@/components/loader/LazyLoading';
|
|
|
|
const Chart = dynamic(() => import('react-apexcharts'), {
|
|
loading: () => <LazyLoading />,
|
|
ssr: false
|
|
});
|
|
|
|
type Props = {
|
|
data: number[]
|
|
labels: string[]
|
|
colors: string[]
|
|
};
|
|
|
|
const DonutChart: FC<Props> = ({ data, labels, colors }) => {
|
|
const { theme, systemTheme } = useTheme()
|
|
|
|
const options: ApexOptions = {
|
|
chart: {
|
|
width: 200,
|
|
height: 200,
|
|
events: {
|
|
click(e, chart, options) {
|
|
// const { seriesIndex, dataPointIndex } = options
|
|
const { selectedDataPoints } = options?.globals
|
|
// console.log(selectedDataPoints)
|
|
if (selectedDataPoints.length > 0) {
|
|
}
|
|
},
|
|
},
|
|
},
|
|
plotOptions: {
|
|
pie: {
|
|
expandOnClick: true,
|
|
donut: {
|
|
size: '55%',
|
|
labels: {
|
|
show: true,
|
|
name: {
|
|
show: true,
|
|
color: theme === 'dark' ? '#fff' : theme === 'system' && systemTheme === 'dark' ? '#fff' : '#000',
|
|
fontSize: '20px',
|
|
fontWeight: 'bold'
|
|
},
|
|
value: {
|
|
show: true,
|
|
color: theme === 'dark' ? '#fff' : theme === 'system' && systemTheme === 'dark' ? '#fff' : '#000',
|
|
fontSize: '32px',
|
|
fontWeight: 'bold'
|
|
},
|
|
total: {
|
|
show: false
|
|
},
|
|
},
|
|
},
|
|
}
|
|
},
|
|
legend: {
|
|
show: false,
|
|
},
|
|
stroke: {
|
|
width: 0
|
|
},
|
|
dataLabels: {
|
|
enabled: true,
|
|
formatter: function (val: any, opts) {
|
|
// console.log(opts)
|
|
return opts?.w.globals.labels[opts.seriesIndex] + ': ' + opts?.w.globals.series[opts.seriesIndex]
|
|
// return opts.w.globals.series[opts.seriesIndex]
|
|
},
|
|
},
|
|
fill: {
|
|
type: 'gradient',
|
|
},
|
|
labels: labels,
|
|
colors: colors,
|
|
responsive: [{
|
|
breakpoint: 800,
|
|
options: {
|
|
chart: {
|
|
width: 200
|
|
}
|
|
}
|
|
}]
|
|
}
|
|
const series = data
|
|
|
|
return (
|
|
<>
|
|
<div className='flex items-center justify-center'>
|
|
<Chart
|
|
type='donut'
|
|
options={options}
|
|
series={series}
|
|
width={250}
|
|
/>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|
|
|
|
export default DonutChart; |