diff --git a/Controleur/ControleurAjaxgraphiquesinistres.php b/Controleur/ControleurAjaxgraphiquesinistres.php index a732cc8..07f2fb3 100755 --- a/Controleur/ControleurAjaxgraphiquesinistres.php +++ b/Controleur/ControleurAjaxgraphiquesinistres.php @@ -45,10 +45,14 @@ class ControleurAjaxgraphiquesinistres extends Controleur { } // --- Mode Vue Ajax HTML --- + // Utilisation de constantes JSON pour sécuriser l'insertion dans le JavaScript + // JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP empêchent le bris du HTML/JS + $optionsJson = JSON_NUMERIC_CHECK | JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP; + $this->genererVueAjax([ - 'dataTabClaims' => json_encode($tabclaims, JSON_NUMERIC_CHECK), - 'dataTabClaimsMonth' => json_encode($tabclaimsMonth, JSON_NUMERIC_CHECK), - 'dataLossRatio' => json_encode($tabLossRatio, JSON_NUMERIC_CHECK) + 'dataTabClaims' => json_encode($tabclaims, $optionsJson), + 'dataTabClaimsMonth' => json_encode($tabclaimsMonth, $optionsJson), + 'dataLossRatio' => json_encode($tabLossRatio, $optionsJson) ]); } } \ No newline at end of file diff --git a/Vue/Accueil/index.php b/Vue/Accueil/index.php index 76b8e85..7edea80 100644 --- a/Vue/Accueil/index.php +++ b/Vue/Accueil/index.php @@ -1,3 +1,5 @@ +//1- Page HTML / PHP:Accueil.php +

@@ -138,7 +140,7 @@
-
@@ -147,38 +149,15 @@
- - -
+ + + + + + + - + \ No newline at end of file diff --git a/Vue/Ajaxgraphiquesinistres/index.php b/Vue/Ajaxgraphiquesinistres/index.php index ba331d7..a79bb97 100644 --- a/Vue/Ajaxgraphiquesinistres/index.php +++ b/Vue/Ajaxgraphiquesinistres/index.php @@ -31,152 +31,188 @@ + - - - - - + } + // --- Initialisation des graphiques --- + // 1. Sinistres par garantie + const ctxPie = document.getElementById('claimsPie'); + if (ctxPie) { + new Chart(ctxPie, { + type: 'doughnut', + data: { + labels: dataClaims.claimsLabels, + datasets: [{ + data: dataClaims.claimsValues + }] + }, + options: { + plugins: { + legend: { position: 'right' } + } + } + }); + } + + // 2. Evolution des sinistres par mois + const ctxLine = document.getElementById('claimsLine'); + if (ctxLine) { + new Chart(ctxLine, { + data: { + labels: dataClaimsMonth.months, + datasets: [ + { + type: 'line', + label: "Cumulés", + data: dataClaimsMonth.monthlyClaims, + borderColor: "blue", + backgroundColor: "rgba(0,0,255,0.2)", + tension: 0.4, + yAxisID: 'y' + }, + { + type: 'bar', + label: "Mensuels", + data: dataClaimsMonth.singleClaims, + backgroundColor: "rgba(255,0,0,0.5)", + borderColor: "red", + borderWidth: 1, + yAxisID: 'y' + } + ] + }, + options: { + responsive: true, + interaction: { + mode: 'index', + intersect: false + }, + stacked: false, + scales: { + y: { + beginAtZero: true, + title: { display: true, text: "Montant des sinistres" } + }, + x: { + title: { display: true, text: "Mois" } + } + } + } + }); + } + + // 3. Sinistralité + const ctxBar = document.getElementById('lossRatioBar'); + if (ctxBar) { + new Chart(ctxBar, { + type: 'bar', + data: { + labels: dataLossRatio.lossRatioLabels, + datasets: [{ + label: "Sinistralité (%)", + data: dataLossRatio.lossRatioValues + }] + }, + options: { + scales: { + y: { + beginAtZero: true, + max: 100 + } + } + } + }); + } + +})(); // Fin de l'IIFE + \ No newline at end of file