From: gregor herrmann Date: Thu, 14 Jun 2018 22:12:41 +0000 (+0200) Subject: format x tick values (datetime) differently according to interval X-Git-Url: https://git.toastfreeware.priv.at/chrisu/seepark.git/commitdiff_plain/8e2b15c9ed5f03146cd999593b4d8515fde79858 format x tick values (datetime) differently according to interval format strings picked a bit randomly for now, following the temperature charts at https://info.comodo.priv.at/webcam/ might make more sense and fun with real values … --- diff --git a/web/static/seepark_web.js b/web/static/seepark_web.js index 399fd86..63bca13 100644 --- a/web/static/seepark_web.js +++ b/web/static/seepark_web.js @@ -1,6 +1,6 @@ var api_base_url = '/api/1/sensor/type/Wassertemperatur?mode=consolidated&format=c3'; -function dayschart(element, interval, days) { +function dayschart(element, interval, days, xtickformat) { var chart = c3.generate({ bindto: '#' + element, size: { @@ -33,7 +33,7 @@ function dayschart(element, interval, days) { x: { type: 'timeseries', tick: { - format: '%Y-%m-%d %H:%M', + format: xtickformat, fit: false, multiline: true, // broken? so → rotate: -90 @@ -75,6 +75,10 @@ function dayschart(element, interval, days) { }, value: function (value, ratio, id, index) { return value.toFixed(2) + '°'; + }, + title: function (x) { + // TODO: format datetime into something readable + return x; } } }, @@ -106,7 +110,7 @@ function beginend(days) { return '&begin=' + begin + '&end=' + end; } -dayschart('chart1', 'Tag', 1); -dayschart('chart7', 'Woche', 7); -dayschart('chart31', 'Monat', 31); -dayschart('chart365', 'Jahr', 365); +dayschart('chart1', 'Tag', 1, '%H:%M'); +dayschart('chart7', 'Woche', 7, '%a %d'); +dayschart('chart31', 'Monat', 31, 'Woche %V'); +dayschart('chart365', 'Jahr', 365, '%b %d');