summaryrefslogtreecommitdiff
path: root/includes/helper/graph_helper.php
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2017-06-20 16:50:21 +0200
committermsquare <msquare@notrademark.de>2017-06-20 16:50:21 +0200
commit56814fa2fdf58b4013f4d57c5ea87619c7122957 (patch)
tree640945769b7e9626cdf43162c786147f5c962029 /includes/helper/graph_helper.php
parenta5fc5bd0979e8de1fce8a8addd351a6e7bd6aeb8 (diff)
parentcd30017b97afc3c7001fbb9eb14b54dbb980b7b6 (diff)
Merge branch 'pr/316' into feature-igel-rewrite
Diffstat (limited to 'includes/helper/graph_helper.php')
-rw-r--r--includes/helper/graph_helper.php56
1 files changed, 29 insertions, 27 deletions
diff --git a/includes/helper/graph_helper.php b/includes/helper/graph_helper.php
index 42a6c07a..12c7df6c 100644
--- a/includes/helper/graph_helper.php
+++ b/includes/helper/graph_helper.php
@@ -2,40 +2,42 @@
/**
* 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
+ *
+ * @param string $dom_id
+ * @param string $key key name of the x-axis
+ * @param array $row_names key names for the data rows
+ * @param array $colors colors for the data rows
+ * @param array $data the data
+ * @return string
*/
-function bargraph($dom_id, $key, $row_names, $colors, $data) {
- $labels = [];
- foreach ($data as $dataset) {
- $labels[] = $dataset[$key];
- }
-
- $datasets = [];
- foreach ($row_names as $row_key => $name) {
- $values = [];
+function bargraph($dom_id, $key, $row_names, $colors, $data)
+{
+ $labels = [];
foreach ($data as $dataset) {
- $values[] = $dataset[$row_key];
+ $labels[] = $dataset[$key];
}
- $datasets[] = [
- 'label' => $name,
- 'fillColor' => $colors[$row_key],
- 'data' => $values
- ];
- }
-
- return '<canvas id="' . $dom_id . '" style="width: 100%; height: 300px;"></canvas>
+
+ $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="' . $dom_id . '" style="width: 100%; height: 300px;"></canvas>
<script type="text/javascript">
$(function(){
var ctx = $("#' . $dom_id . '").get(0).getContext("2d");
var chart = new Chart(ctx).Bar(' . json_encode([
- 'labels' => $labels,
- 'datasets' => $datasets
- ]) . ');
+ 'labels' => $labels,
+ 'datasets' => $datasets
+ ]) . ');
});
</script>';
}
-
-?> \ No newline at end of file