summaryrefslogtreecommitdiff
path: root/includes/helper
diff options
context:
space:
mode:
authorPhilip Häusler <msquare@notrademark.de>2015-08-16 23:08:02 +0200
committerPhilip Häusler <msquare@notrademark.de>2015-08-16 23:13:13 +0200
commitc4ee004095b178cc85767a9848e8cfc798acc369 (patch)
tree71a1e014f942e84054f1fd679ca49cb62ff90c3d /includes/helper
parent9d7389baeb1d3aaf427f65a373c1909d5e7b5340 (diff)
rework arrival stat graphs and tables
Diffstat (limited to 'includes/helper')
-rw-r--r--includes/helper/graph_helper.php39
1 files changed, 39 insertions, 0 deletions
diff --git a/includes/helper/graph_helper.php b/includes/helper/graph_helper.php
new file mode 100644
index 00000000..17473634
--- /dev/null
+++ b/includes/helper/graph_helper.php
@@ -0,0 +1,39 @@
+<?php
+
+/**
+ * Renders a bargraph
+ * @param string $key keyname of the x-axis
+ * @param array $row_names keynames for the data rows
+ * @param unknown $colors colors for the data rows
+ * @param unknown $data the data
+ */
+function bargraph($id, $key, $row_names, $colors, $data) {
+ $labels = [];
+ foreach ($data as $dataset)
+ $labels[] = $dataset[$key];
+
+ $datasets = [];
+ foreach ($row_names as $row_key => $name) {
+ $values = [];
+ foreach ($data as $dataset)
+ $values[] = $dataset[$row_key];
+ $datasets[] = [
+ 'label' => $name,
+ 'fillColor' => $colors[$row_key],
+ 'data' => $values
+ ];
+ }
+
+ return '<canvas id="' . $id . '" style="width: 100%; height: 300px;"></canvas>
+ <script type="text/javascript">
+ $(function(){
+ var ctx = $("#' . $id . '").get(0).getContext("2d");
+ var chart = new Chart(ctx).Bar(' . json_encode([
+ 'labels' => $labels,
+ 'datasets' => $datasets
+ ]) . ');
+ });
+ </script>';
+}
+
+?> \ No newline at end of file