<?php
$i=1;
foreach($tabDebniveau as $divdeb) {
	$tabDay[$i] = array();
	$nivcolor = mysqli_query($bdd,"SELECT bgcolor FROM ".$prefix."_edtnivcolor WHERE niveau = '".$divdeb."'");
	$nivcolor_info = mysqli_fetch_assoc($nivcolor);
	$tabColor[$i] = $nivcolor_info['bgcolor'];
	foreach (new DatePeriod($jourP1date, new DateInterval('P1D') /* pas d'un jour */, $jourP2date) as $dt) {
		$date = $dt->format('Y-m-d');
		$nbeleves = 0;
		$elegrap_nb = mysqli_query($bdd,"SELECT nombre FROM ".$prefix."_freqgrappes WHERE date_freq = '".$dt->format('Y-m-d')."' AND niveau = '".$divdeb."' AND passage = '1' ".$filtre_activs."");
		while($elegrap = mysqli_fetch_assoc($elegrap_nb)) {
			$nbeleves += $elegrap['nombre'];
		}
		array_push($tabDay[$i], $nbeleves);
	}
	$i++;
}
?>
<div id="wrapper" class="statcadre">
<canvas id="chart_passperdayperniv" class="charts"></canvas>
</div>
<script type="text/javascript">
(async function() {
    
    Chart.register(ChartDataLabels);
    const labels = <?php echo json_encode($tabDays); ?>;
    const data = {
      labels: labels,
      datasets: [ 
		<?php $i=1;$j=1;
		foreach($tabDebniveau as $divdeb) { ?>
		{
			label: <?php echo json_encode($tabNiveau[$i-1]); ?>,
			data: <?php echo json_encode($tabDay[$i]); ?>,
			backgroundColor: '<?php echo $tabColor[$i] ?>',
			borderColor: '<?php echo $tabColor[$i] ?>',
			borderWidth: 1
		} <?php if($j<count($tabDebniveau)) { echo ','; } $i++; $j++;} ?> ]
    };
new Chart(
    document.getElementById('chart_passperdayperniv'),
    {
    type: 'bar',
    data: data,
    options: {
        plugins: {
            title: {
                display: true,
                text: "<?php echo FDIR_STATS_INF23; ?>"
            },
            legend: {
                display:false
            },
            tooltip : {
                mode: 'point',
                intersect: false,
              }  ,    
            datalabels: {
              display: true, // Affiche les étiquettes de données
              color: '#fff', // Couleur du texte
              align: 'center', // Alignement horizontal
              anchor: 'center', // Alignement vertical
              font: {
                weight: 'bold', // Style de police
              },
              display: function(context) {
                    return false; // Ne pas afficher les étiquettes de données
                },
            },
        },
        responsive: true,
        maintainAspectRatio: false,
        scales: {
            yAxes: [{
                ticks: {
                    beginAtZero:true
                }
            }]
        },
      }
    }
);
})();
</script>