format x tick values (datetime) differently according to interval
authorgregor herrmann <gregor@toastfreeware.priv.at>
Thu, 14 Jun 2018 22:12:41 +0000 (00:12 +0200)
committergregor herrmann <gregor@toastfreeware.priv.at>
Thu, 14 Jun 2018 22:12:41 +0000 (00:12 +0200)
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 …

web/static/seepark_web.js

index 399fd86445cb39e5bac5abc4eb439647d5713bc3..63bca132533275b3cd42f35048aa4503c22f4ab1 100644 (file)
@@ -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');