mirror of
https://forge.chapril.org/tykayn/osm-commerces
synced 2025-10-04 17:04:53 +02:00
up graph
This commit is contained in:
parent
93086eba60
commit
acb71e45e0
2 changed files with 49 additions and 3 deletions
|
@ -213,8 +213,8 @@ class FraicheurController extends AbstractController
|
|||
}
|
||||
|
||||
foreach ($ecartsMoyenne as $ville) {
|
||||
// Histogramme écart à la moyenne (pas de 10%)
|
||||
$binEcart = (string)(ceil($ville['ecart_moyenne_pourcent'] / 10) * 10);
|
||||
// Histogramme écart à la moyenne (pas de 3%)
|
||||
$binEcart = (string)(ceil($ville['ecart_moyenne_pourcent'] / 3) * 3);
|
||||
if (!isset($histogramEcartMoyenne[$binEcart])) {
|
||||
$histogramEcartMoyenne[$binEcart] = 0;
|
||||
}
|
||||
|
|
|
@ -249,6 +249,7 @@
|
|||
<div class="card mt-4">
|
||||
{% include 'admin/stats_history.html.twig' %}
|
||||
<div id="distribution_completion" class="mt-4 mb-4"></div>
|
||||
<div id="distribution_budget_habitant" class="mt-4 mb-4"></div>
|
||||
|
||||
|
||||
<div class="row">
|
||||
|
@ -656,7 +657,52 @@ if(dc ){
|
|||
}else{
|
||||
console.log('pas de distribution_completion')
|
||||
}
|
||||
|
||||
|
||||
// === Distribution du budget par habitant (écart à la moyenne, pas de 3%) ===
|
||||
const budgetEcartData = [];
|
||||
{% for commerce in stats.places %}
|
||||
{% if commerce.getBudgetParHabitantEcartPourcent is defined %}
|
||||
budgetEcartData.push({{ commerce.getBudgetParHabitantEcartPourcent()|default(0) }});
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
const budgetEcartDistribution = {};
|
||||
budgetEcartData.forEach(ecart => {
|
||||
const range = Math.floor(ecart / 3) * 3;
|
||||
const key = `${range}% à ${range + 3}%`;
|
||||
budgetEcartDistribution[key] = (budgetEcartDistribution[key] || 0) + 1;
|
||||
});
|
||||
const budgetEcartLabels = Object.keys(budgetEcartDistribution).sort((a, b) => parseInt(a) - parseInt(b));
|
||||
const budgetEcartValues = budgetEcartLabels.map(label => budgetEcartDistribution[label]);
|
||||
const dbh = document.getElementById('distribution_budget_habitant');
|
||||
if(dbh){
|
||||
const budgetEcartCtx = dbh.getContext ? dbh.getContext('2d') : null;
|
||||
if(!budgetEcartCtx){
|
||||
console.log('pas de budgetEcartCtx');
|
||||
} else {
|
||||
new Chart(budgetEcartCtx, {
|
||||
type: 'bar',
|
||||
data: {
|
||||
labels: budgetEcartLabels,
|
||||
datasets: [{
|
||||
label: 'Distribution des villes selon l\'écart à la moyenne du budget par habitant (pas 3%)',
|
||||
data: budgetEcartValues,
|
||||
backgroundColor: 'rgba(255, 206, 86, 0.5)',
|
||||
borderColor: 'rgba(255, 206, 86, 1)',
|
||||
borderWidth: 1
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
scales: {
|
||||
y: {
|
||||
beginAtZero: true
|
||||
}
|
||||
},
|
||||
responsive: true,
|
||||
maintainAspectRatio: false
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue