From 9cbf2091f481e7cae5697e38bf4be6198e6c0b86 Mon Sep 17 00:00:00 2001 From: KONE SOREL Date: Tue, 30 Dec 2025 19:24:54 +0000 Subject: [PATCH] var --- Js/fonctions.js | 167 +++++++++++++++++++----------------------------- Vue/gabarit.php | 2 +- 2 files changed, 68 insertions(+), 101 deletions(-) diff --git a/Js/fonctions.js b/Js/fonctions.js index e26d73a..447ff29 100755 --- a/Js/fonctions.js +++ b/Js/fonctions.js @@ -809,7 +809,6 @@ function afficher_adherents_police() } function graphique_sinistre() { - // Spinner pendant le chargement $("#div_graphique").html(`
@@ -820,107 +819,75 @@ function graphique_sinistre() { `); $.ajax({ - url: $("#racineWeb").val() + "Ajaxgraphiquesinistres/", - type: 'post', - success: function(data, textStatus, jqXHR) { - let contentType = jqXHR.getResponseHeader("Content-Type"); + url: $("#racineWeb").val() + "Ajaxgraphiquesinistres/?api=1", + type: 'get', + dataType: 'json', + success: function(data) { + $("#div_graphique").empty(); - if (contentType && contentType.indexOf("application/json") !== -1) { - // --- Mode JSON --- - $("#div_graphique").empty(); - - // Layout responsive Bootstrap - $("#div_graphique").append(` -
-
-
-
-
Répartition des sinistres
- -
-
-
-
-
-
-
Évolution mensuelle
- -
-
-
-
-
-
-
Ratio de sinistralité
- -
-
-
-
- `); - - // Graphique 1 : répartition - new Chart(document.getElementById('claimsChart'), { - type: 'bar', - data: { - labels: data.claims.claimsLabels, - datasets: [{ - label: 'Nombre de sinistres', - data: data.claims.claimsValues, - backgroundColor: 'rgba(54, 162, 235, 0.6)' - }] - } - }); - - // Graphique 2 : évolution mensuelle - new Chart(document.getElementById('claimsMonthChart'), { - type: 'line', - data: { - labels: data.claimsMonth.months, - datasets: [ - { - label: 'Sinistres mensuels', - data: data.claimsMonth.monthlyClaims, - borderColor: 'rgba(255, 99, 132, 0.8)', - fill: false - }, - { - label: 'Sinistres uniques', - data: data.claimsMonth.singleClaims, - borderColor: 'rgba(75, 192, 192, 0.8)', - fill: false - } - ] - } - }); - - // Graphique 3 : ratio - new Chart(document.getElementById('lossRatioChart'), { - type: 'line', - data: { - labels: data.lossRatio.lossRatioLabels, - datasets: [{ - label: 'Ratio de sinistralité', - data: data.lossRatio.lossRatioValues, - borderColor: 'rgba(255, 206, 86, 0.8)', - fill: false - }] - } - }); - - } else { - // --- Mode Vue HTML --- - $("#div_graphique").html(data); - } - }, - error: function(err) { - console.error("Erreur AJAX:", err); - $("#div_graphique").html(` -
- Impossible de charger les graphiques. + // Construis ton layout HTML ici + $("#div_graphique").append(` +
+
+
+
`); + + + // Initialise les graphiques avec Chart.js + // Graphique 1 : répartition des sinistres + new Chart(document.getElementById('claimsChart'), { + type: 'bar', + data: { + labels: data.claims.claimsLabels, + datasets: [{ + label: 'Nombre de sinistres', + data: data.claims.claimsValues, + backgroundColor: 'rgba(54, 162, 235, 0.6)' + }] + } + }); + + // Graphique 2 : évolution mensuelle + new Chart(document.getElementById('claimsMonthChart'), { + type: 'line', + data: { + labels: data.claimsMonth.months, + datasets: [ + { + label: 'Sinistres mensuels', + data: data.claimsMonth.monthlyClaims, + borderColor: 'rgba(255, 99, 132, 0.8)', + fill: false + }, + { + label: 'Sinistres uniques', + data: data.claimsMonth.singleClaims, + borderColor: 'rgba(75, 192, 192, 0.8)', + fill: false + } + ] + } + }); + + // Graphique 3 : ratio de sinistralité + new Chart(document.getElementById('lossRatioChart'), { + type: 'line', + data: { + labels: data.lossRatio.lossRatioLabels, + datasets: [{ + label: 'Ratio de sinistralité', + data: data.lossRatio.lossRatioValues, + borderColor: 'rgba(255, 206, 86, 0.8)', + fill: false + }] + } + }); + + }, + error: function(err) { + $("#div_graphique").html(`
Impossible de charger les graphiques.
`); } }); -} - +} \ No newline at end of file diff --git a/Vue/gabarit.php b/Vue/gabarit.php index 547f889..e0f3c60 100755 --- a/Vue/gabarit.php +++ b/Vue/gabarit.php @@ -599,7 +599,7 @@ $activeChildId = $menuData['child']; - +