mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 21:06:29 +00:00
initial commit for new hats app
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
'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;
|
||||
Reference in New Issue
Block a user