Files
Time-in-Pie/components/CategoryChart.tsx
T
2026-08-04 12:16:06 +02:00

62 lines
1.5 KiB
TypeScript

'use client';
import { Chart as ChartJS, ArcElement, Tooltip, Legend } from 'chart.js';
import { Pie } from 'react-chartjs-2';
// Chart.js Module registrieren (wichtig in v3/v4)
ChartJS.register(ArcElement, Tooltip, Legend);
interface CategoryChartProps {
times: Record<string, number>;
}
export default function CategoryChart({ times }: CategoryChartProps) {
const labels = Object.keys(times);
const dataValues = Object.values(times);
const data = {
labels,
datasets: [
{
label: 'Dauer (in Minuten)',
data: dataValues,
backgroundColor: [
'#3b82f6', // Blau
'#10b981', // Grün
'#f59e0b', // Orange
'#ef4444', // Rot
'#8b5cf6', // Violett
'#ec4899', // Pink
'#64748b', // Grau
],
borderColor: '#ffffff',
borderWidth: 2,
},
],
};
const options = {
responsive: true,
plugins: {
legend: {
position: 'bottom' as const,
},
tooltip: {
callbacks: {
label: (context: any) => {
const minutes = context.raw || 0;
const hours = Math.floor(minutes / 60);
const remainingMins = Math.round(minutes % 60);
return ` ${context.label}: ${hours} Std. ${remainingMins} Min. (${minutes} Min.)`;
},
},
},
},
};
return (
<div style={{ maxWidth: '360px', margin: '1.5rem auto' }}>
<Pie data={data} options={options} />
</div>
);
}