Better Graphs #3

This commit is contained in:
JonatanRek 2019-09-28 20:21:48 +02:00
parent 93e2e04e98
commit 7e047ee0a3
1 changed files with 61 additions and 17 deletions

View File

@ -72,7 +72,8 @@ class Ajax extends Template
$output[$key]['y'] = 0; $output[$key]['y'] = 0;
}*/ }*/
$output[$key]['y'] = $value; $output[$key]['y'] = $value;
$output[$key]['t'] = (new DateTime($arrayTime[$key]))->format("hA"); $timeStamp = new DateTime($arrayTime[$key]);
$output[$key]['t'] = $timeStamp->format("Y-m-d") . 'T' . $timeStamp->format("H:i:s") . 'Z';
} }
@ -87,27 +88,58 @@ foreach ($arrayTimeStamps as $key => $value) {
$labels = json_encode($arrayTimeStamps); $labels = json_encode($arrayTimeStamps);
$range = RANGES[$subDevice['type']]; $range = RANGES[$subDevice['type']];
header('Content-Type: application/json'); header('Content-Type: application/json');
$JSON = '{ /*$JSON = '{
"type": "line", "type": "line",
"data": {
"labels": ' . $data . ',
"datasets": [{
"data": ' . $data . ',
"backgroundColor": "#7522bf",
"lineTension": 0,
"radius": 5
}]
},
"options": {
"legend": {
"display": false
},
"scales": {
"xAxes": [{
"type": "time",
"time": {
"unit": "hour"
}
}],
"yAxes": [{
"ticks": {
"min": ' . $range['min'] . ',
"max": ' . $range['max'] . ',
"steps": ' . $range['scale'] . '
}
}]
},
"tooltips": {
"enabled": false
},
"hover": {
"mode": null
}
}
}';*/
$JSON = '
{
"type": "bar",
"data": { "data": {
"labels": ' . $labels . ',
"datasets": [{ "datasets": [{
"data": ' . $data . ', "data": ' . $data . '
"backgroundColor": "#7522bf",
"lineTension": 0,
"radius": 5
}] }]
}, },
"options": { "options": {
"legend": {
"display": false
},
"scales": { "scales": {
"xAxes": [{ "xAxes": [{
"type": "time", "type": "time",
"time": { "distribution": "linear"
"unit": "hour"
}
}], }],
"yAxes": [{ "yAxes": [{
"ticks": { "ticks": {
@ -117,14 +149,26 @@ $JSON = '{
} }
}] }]
}, },
"legend": {
"display": false
},
"tooltips": { "tooltips": {
"enabled": false "enabled": true
}, },
"hover": { "hover": {
"mode": null "mode": true
} }
} }
}'; }
';
/*
*/
echo $JSON; echo $JSON;
die(); die();