32 lines
657 B
JavaScript
32 lines
657 B
JavaScript
function renderChart(points) {
|
|
const canvas = document.getElementById("consumption-chart");
|
|
|
|
const labels = points.map(p => formatPeriod(p.period));
|
|
const data = points.map(p => p.delta_m3);
|
|
|
|
new Chart(canvas, {
|
|
type: "bar",
|
|
data: {
|
|
labels,
|
|
datasets: [
|
|
{
|
|
label: "Consommation (m³)",
|
|
data
|
|
},
|
|
],
|
|
},
|
|
options: {
|
|
responsive: true,
|
|
scales: {
|
|
y: {
|
|
beginAtZero: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
}
|
|
|
|
function formatPeriod(isoString) {
|
|
const date = new Date(isoString);
|
|
return date.toLocaleDateString("fr-FR", { day: "2-digit", month: "short" });
|
|
}
|