Files
hats-app/app/admin/administration/user/component/EmployeePerformance/DonutChart.tsx
T
Ichsan Kurniawan a160eccddf fixing typescript error during production build
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.
2026-04-23 21:36:42 +07:00

101 lines
2.9 KiB
TypeScript

'use client'
import { FC } from 'react';
import Chart from 'react-apexcharts';
import { type ApexOptions } from 'apexcharts';
import { useTheme } from 'next-themes';
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;