import React from 'react'; import { Chart as ChartJS, CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip, Legend } from 'chart.js'; import { Line } from 'react-chartjs-2'; import '../styles/ChartModal.css'; ChartJS.register(CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip, Legend); interface ChartModalProps { isOpen: boolean; kpi: any; measurements: any[]; onClose: () => void; } export const ChartModal: React.FC = ({ isOpen, kpi, measurements, onClose }) => { if (!isOpen || !kpi) return null; // Préparer les données pour le graphique const labels = measurements .map(m => new Date(m.measurement_date).toLocaleDateString('fr-FR')) .reverse(); const values = measurements .map(m => m.value) .reverse(); const chartData = { labels, datasets: [ { label: kpi.name, data: values, borderColor: '#6496ff', backgroundColor: 'rgba(100, 150, 255, 0.1)', tension: 0.4, fill: true, pointRadius: 4, pointBackgroundColor: '#6496ff', pointBorderColor: '#fff', pointBorderWidth: 2, }, ], }; const chartOptions = { responsive: true, maintainAspectRatio: false, plugins: { legend: { display: true, position: 'top' as const, }, title: { display: true, text: `Graphique Complet: ${kpi.name}`, font: { size: 16, weight: 'bold' as const }, }, }, scales: { y: { beginAtZero: true, title: { display: true, text: kpi.unit, }, }, x: { display: true, }, }, }; return (
e.stopPropagation()}>

📈 {kpi.name}

Nombre de mesures: {measurements.length}

Période: {labels[0]} à {labels[labels.length - 1]}

); };