Ajout de graphes (et d'un .gitignore)
This commit is contained in:
parent
646b841634
commit
c2c9ff2c50
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*.html
|
||||||
|
barometre.sqlite
|
@ -1,3 +1,10 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Suivi du baromètre</title>
|
||||||
|
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.1/chart.umd.min.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$villes_ALM = array(49007, 49015, 49020, 49028, 49035, 49048, 49055, 4129, 49130, 49135, 49307, 49200, 49214, 49223, 49241, 49246, 49377, 49267, 49271, 49294, 49298, 49306, 49278, 49326, 49329, 49338, 49339, 49353, 49434);
|
$villes_ALM = array(49007, 49015, 49020, 49028, 49035, 49048, 49055, 4129, 49130, 49135, 49307, 49200, 49214, 49223, 49241, 49246, 49377, 49267, 49271, 49294, 49298, 49306, 49278, 49326, 49329, 49338, 49339, 49353, 49434);
|
||||||
@ -40,8 +47,58 @@ while( $line = $compte->fetchArray()) {
|
|||||||
echo "<tr><td>{$line['nom']}</td><td>{$line['nombre']}</td></tr>\n";
|
echo "<tr><td>{$line['nom']}</td><td>{$line['nombre']}</td></tr>\n";
|
||||||
}
|
}
|
||||||
?></table>
|
?></table>
|
||||||
|
<hr/>
|
||||||
|
<div style="width: 75%; margin:0 auto;"><canvas id="graphe"></canvas></div>
|
||||||
|
<?php
|
||||||
|
$data = $base->query("SELECT * FROM chiffres c natural join villes v WHERE v.nom != 'Angers'");
|
||||||
|
$dataset = [];
|
||||||
|
while($line = $data->fetchArray()) {
|
||||||
|
if (!key_exists($line['code_INSEE'], $dataset)) {
|
||||||
|
$dataset[$line['code_INSEE']]['type'] = 'line';
|
||||||
|
$dataset[$line['code_INSEE']]['label'] = $line['nom'];
|
||||||
|
$dataset[$line['code_INSEE']]['tension'] = 0.1;
|
||||||
|
}
|
||||||
|
$dataset[$line['code_INSEE']]['data'][] = array('x' => date_format(date_create($line['date']), 'Y/m/d H:i'), 'y'=>$line['nombre']);
|
||||||
|
}
|
||||||
|
$decoded = [];
|
||||||
|
foreach($dataset as $value) { $decoded[] = $value; }
|
||||||
|
$json = json_encode($decoded);
|
||||||
|
?>
|
||||||
|
<script type="text/javascript">
|
||||||
|
const data = <?=$json?>;
|
||||||
|
(async function() {
|
||||||
|
const myChart = new Chart(document.getElementById('graphe'), {
|
||||||
|
type: 'line',
|
||||||
|
data: {
|
||||||
|
datasets : data
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
<hr/>
|
||||||
|
<div style="width: 75%; margin:0 auto;"><canvas id="graphe_angers"></canvas></div>
|
||||||
|
<?php
|
||||||
|
$data = $base->query("SELECT * FROM chiffres c natural join villes v WHERE v.nom == 'Angers'");
|
||||||
|
$dataset_angers = [];
|
||||||
|
while($line = $data->fetchArray()) {
|
||||||
|
$dataset_angers[] = array('x' => date_format(date_create($line['date']), 'Y/m/d H:i'), 'y'=>$line['nombre']);
|
||||||
|
}
|
||||||
|
$json_angers = json_encode($dataset_angers);
|
||||||
|
?>
|
||||||
|
<script type="text/javascript">
|
||||||
|
const data_angers = <?=$json_angers?>;
|
||||||
|
(async function() {
|
||||||
|
const myChart = new Chart(document.getElementById('graphe_angers'), { type:'line', data: {datasets: [{
|
||||||
|
type: 'line',
|
||||||
|
label:"Angers",
|
||||||
|
data: data_angers,
|
||||||
|
tension: 0.1
|
||||||
|
}]}});
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
<hr/>
|
||||||
<div style="position: fixed; bottom:0; width:100%;">
|
<div style="position: fixed; bottom:0; width:100%;">
|
||||||
<a href="https://git.fedaya.net/Fedaya/progression_barometre">Le code correspondant au script</a>
|
<a href="https://git.fedaya.net/Fedaya/progression_barometre">Le code correspondant au script</a>
|
||||||
</div>
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
BIN
barometre.sqlite
BIN
barometre.sqlite
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user