Better Graphs #3

This commit is contained in:
JonatanRek 2019-09-28 20:21:48 +02:00
parent 93e2e04e98
commit 7e047ee0a3

View File

@ -72,7 +72,8 @@ class Ajax extends Template
$output[$key]['y'] = 0;
}*/
$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,10 +88,10 @@ foreach ($arrayTimeStamps as $key => $value) {
$labels = json_encode($arrayTimeStamps);
$range = RANGES[$subDevice['type']];
header('Content-Type: application/json');
$JSON = '{
/*$JSON = '{
"type": "line",
"data": {
"labels": ' . $labels . ',
"labels": ' . $data . ',
"datasets": [{
"data": ' . $data . ',
"backgroundColor": "#7522bf",
@ -124,7 +125,50 @@ $JSON = '{
"mode": null
}
}
}';
}';*/
$JSON = '
{
"type": "bar",
"data": {
"datasets": [{
"data": ' . $data . '
}]
},
"options": {
"scales": {
"xAxes": [{
"type": "time",
"distribution": "linear"
}],
"yAxes": [{
"ticks": {
"min": ' . $range['min'] . ',
"max": ' . $range['max'] . ',
"steps": ' . $range['scale'] . '
}
}]
},
"legend": {
"display": false
},
"tooltips": {
"enabled": true
},
"hover": {
"mode": true
}
}
}
';
/*
*/
echo $JSON;
die();