verlaufsgrafik

This commit is contained in:
Walter Hupfeld
2023-10-10 18:45:24 +02:00
parent 918dfb0630
commit d113c5bd09
7 changed files with 708 additions and 15 deletions

View File

@@ -16,7 +16,7 @@ function get_unfallzahlen($numYear,$strLocation) {
function get_beteiligte($numYear,$strLocation) {
global $db;
$strSQL="SELECT
sum(IstRad) as rad,
-- sum(IstRad) as rad,
sum(IstPKW) as pkw,
sum(IstFuss) as fuss,
sum(IstKrad) as krad,
@@ -72,3 +72,58 @@ function get_series_beteiligte($arrData,$arrBezeichnung){
return $result;
}
function get_verlauf($strLocation){
global $db;
$strSQL="SELECT
UJAHR, UKATEGORIE, count(UKATEGORIE) as anz
FROM data
WHERE IstRad=1 $strLocation
GROUP BY UJAHR,UKATEGORIE
ORDER BY UJAHR";
$result = $db->query($strSQL);
$arrResult = array();
while ($row = $result->fetch(PDO::FETCH_ASSOC)){
$arrResult[$row['UJAHR']][$row['UKATEGORIE']]=$row['anz'];
}
return $arrResult;
}
function get_row($arrData,$kategorie){
global $numStartYear;
global $numLatestYear;
$strResult="";
if ($kategorie==0) {
for ($i=$numLatestYear;$i>=$numStartYear;$i--){
$numAnzahl=0;
for ($kat=0;$kat<=3;$kat++) {
$numAnzahl+=(isset($arrData[$i][$kat])) ? $arrData[$i][$kat] : 0;
}
$strResult.="<td><strong>".$numAnzahl."</strong></td>";
}
} else {
for ($i=$numLatestYear;$i>=$numStartYear;$i--){
$strResult.="<td>";
$strResult.= (isset($arrData[$i][$kategorie])) ? $arrData[$i][$kategorie] : "0";
$strResult.="</td>";
}
}
return $strResult;
}
function get_series_verlauf($arrData,$arrBezeichnung){
global $numStartYear;
global $numLatestYear;
$strResult="[";
foreach ($arrBezeichnung as $key => $bezeichnung) {
$strResult .= "{ name: '".$bezeichnung."', data : [";
for ($i=$numLatestYear;$i>=$numStartYear;$i--){
$strResult .= (isset($arrData[$i][$key])) ? $arrData[$i][$key] : 0;
$strResult .=",";
}
$strResult=substr($strResult,0,-1)
; $strResult.="]},";
}
$strResult.="]";
return $strResult;
}

View File

@@ -1,12 +1,12 @@
<?php
require_once("../config.php");
require_once("../lib/attributes.php");
require_once("include.php");
require_once("functions.php");
$numLand=5; // NRW
$numRegbez=(isset($_GET['regbez'])) ? (int)$_GET['regbez'] : 1;
$numKreis=(isset($_GET['kreis'])) ? (int)$_GET['kreis'] : 1;
$numGemeinde=(isset($_GET['gemeinde'])) ? (int)$_GET['gemeinde'] : 1;
$numJahr=2022;
$numJahr=$numLatestYear;
// Name, Population und Fläche der Gemeinde
$result= $db->prepare("SELECT * FROM community WHERE ULAND=:land AND UREGBEZ=:regbez AND UKREIS=:kreis AND UGEMEINDE=:gemeinde");
@@ -29,6 +29,7 @@
$resultUnfallart = get_unfallart($numJahr,$strLocation);
$resultUnfalltyp = get_unfalltyp($numJahr,$strLocation);
$resultBeteiligte = get_beteiligte($numJahr,$strLocation);
$resultVerlauf = get_verlauf($strLocation);
$numGesamt=0;
?>
@@ -40,11 +41,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Fahrrad-Unfallstatistik NRW</title>
<link rel="stylesheet" href="../css/bootstrap.min.css"/>
<link rel="stylesheet" href="//cdn.datatables.net/1.13.6/css/jquery.dataTables.min.css">
<script src="../js/jquery.min.js"></script>
<script src="//cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="../js/highcharts.js"></script>
<style>
.rechts {text-align:right;background-color:#eee;}
.l {border-left: 1px solid black; }
@@ -83,13 +81,30 @@
<div class="container" style="margin-top:4em;">
<h1>Fahrradunfälle in <?=$strName?></h2>
Einwohnerzahl:<?=$numPopulation?>&nbsp;&nbsp; Fläche:<?=$numFlaeche?> km<sup>2</sup>
<h1>Fahrradunfälle <?=$numJahr?> in <?=$strName?></h2>
<p>Einwohnerzahl: <?=$numPopulation?>&nbsp;&nbsp; Fläche: <?=$numFlaeche?> km<sup>2</sup></p>
<!-- Unfallverlauf -->
<div class="row">
<div class="col-5">
<h4>Unfallverlauf von <?=$numStartYear?> bis <?=$numLatestYear?> </h4>
<table class='table table-sm'>
<tr><th></th><th>2022</th><th>2021</th><th>2020</th><th>2019</th></tr>
<tr><td><?= $arrCategory[1]?></td><?= get_row($resultVerlauf,1) ?></tr>
<tr><td><?= $arrCategory[2]?></td><?= get_row($resultVerlauf,2) ?></tr>
<tr><td><?= $arrCategory[3]?></td><?= get_row($resultVerlauf,3) ?></tr>
<tr><th>Gesamt</th><?= get_row($resultVerlauf,0) ?></tr>
</table>
</div>
<div class="col-7">
<div id="c_unfallverlauf"></div>
</div>
</div>
<!-- Unfallzahlen -->
<h2>Unfallzahlen</h2>
<div class="row">
<div class="col-5">
<div class="col-5">
<h4>Unfallzahlen</h4>
<table class="table table-sm">
<?php
//DEBUG echo "<pre>"; print_r($resultUnfallzahlen);echo "</pre>";
@@ -163,7 +178,6 @@
</div>
</div>
</div>
<?= get_series_beteiligte($resultBeteiligte,$arrBeteiligte) ?>
</body>
<script>
@@ -312,5 +326,52 @@ Highcharts.chart('c_unfallbeteiligte', {
data: <?= get_series_beteiligte($resultBeteiligte,$arrBeteiligte) ?>
}]
});
Highcharts.chart('c_unfallverlauf', {
chart: {
type: 'column'
},
title: {
text: 'Verlauf der Fahrradunfälle',
align: 'center'
},
xAxis: {
categories: ['2022','2021','2020','2019']
},
yAxis: {
min: 0,
title: {
text: 'Jahr'
},
stackLabels: {
enabled: true
}
},
legend: {
align: 'left',
x: 100,
verticalAlign: 'top',
y: 30,
floating: true,
backgroundColor:
Highcharts.defaultOptions.legend.backgroundColor || 'white',
borderColor: '#CCC',
borderWidth: 1,
shadow: false
},
tooltip: {
headerFormat: '<b>{point.x}</b><br/>',
pointFormat: '{series.name}: {point.y}<br/>Total: {point.stackTotal}'
},
plotOptions: {
column: {
stacking: 'normal',
dataLabels: {
enabled: true
}
}
},
series: <?=get_series_verlauf($resultVerlauf,$arrCategory)?>
});
</script>
</html>

View File

@@ -142,7 +142,7 @@ while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
</body>
<script>
let table = new DataTable('#unfallzahlen',{
pageLength : 50
pageLength : 10
});
</script>
</html>

View File

@@ -75,6 +75,7 @@
require("../config.php");
$strSQL="SELECT d.title as Kreis,
district,
SUM(UJAHR=2022) as Jahr_2022,
SUM(UJAHR=2021) as Jahr_2021,
SUM(UJAHR=2020) as Jahr_2020,
@@ -106,7 +107,7 @@ $result=$db->query($strSQL);
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
echo "<tr>";
echo "<td>".$row['Kreis']."</td>";
echo "<td><a href='../index.php?d=".$row['district'],"'>".$row['Kreis']."</a></td>";
echo "<td class='l'>".$row['Jahr_2022']."</td>";
echo "<td>".$row['Jahr_2021']."</td>";
echo "<td>".$row['Jahr_2020']."</td>";
@@ -133,7 +134,7 @@ while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
<script>
let table = new DataTable('#unfallzahlen',{
pageLength : 25
pageLength : 10
});
</script>
</div>