1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| <!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.1/chart.umd.min.js" integrity="sha512-CQBWl4fJHWbryGE+Pc7UAxWMUMNMWzWxF4SQo9CgkJIN1kx6djDQZjh3Y8SZ1d+6I+1zze6Z7kHXO7q3UyZAWw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
</head>
<body>
<script>
"use strict";
const donnees = {
"juin 2024" : {"clous" : 45, "vis" : 48, "autres" : 4},
"juillet 2024" : {"clous" : 45, "vis" : 3, "autres" : 0},
"aout 2024" : {"clous" : 37, "vis" : 42, "autres" : 6},
};
const data = {
labels: Object.keys(donnees),
datasets: [],
};
const premier_element = Object.entries(donnees)[0][1];
Object.keys(premier_element).forEach(type => {
data["datasets"].push({
"label" : type,
"data" : Object.entries(donnees).map(ligne => ligne[1][type]),
});
});
const config = {
type: 'line',
data: data,
options: {
responsive: true,
interaction: {
mode: 'index',
intersect: false,
},
stacked: false,
plugins: {
title: {
display: true,
text: 'Titre du graphique'
}
},
scales: {
y: {
type: 'linear',
display: true,
position: 'left',
},
},
},
};
document.addEventListener("DOMContentLoaded", e => {
new Chart(document.getElementById('graphique'), config);
});
</script>
<div style="width : 800px;"><canvas id="graphique"></canvas></div>
</body>
</html> |
Partager