'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 = ({ 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 ( <>
); } export default DonutChart;