-
Notifications
You must be signed in to change notification settings - Fork 2
/
demo
52 lines (46 loc) · 1.07 KB
/
demo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* PRAGMA table_info( weather ); */
SELECT
locationId, time, AtmosphericPressure
FROM
weather
WHERE
time > '2004-01-01' AND
time < '2004-01-02' AND
locationId NOT IN ( 'M2', 'M4A' );
----
// map results into arrays by location
var byLocation = [];
window.values.forEach( row => {
if ( row[0] in byLocation )
byLocation[ row[0] ].push( { x: row[1], y: row[2] } )
else
byLocation[ row[0] ] = [ { x: row[1], y: row[2] } ]
} )
// configure ChartJS datasets
var datasets = [];
for ( const [ key, value ] of Object.entries( byLocation ) ) {
datasets.push( {
data: byLocation[ key ],
label: key + ' (' + window.locations[ key ].name + ')',
borderColor: window.locations[ key ].colour,
fill: false
} )
}
window.chart = new Chart( document.getElementById( 'chart' ), {
type: 'line',
data: {
datasets: datasets
},
options: {
scales: {
x: { type: 'time', time: { unit: 'hour' } }
},
layout: {
padding: {
bottom: 15
}
},
responsive: true,
maintainAspectRatio: false
}
} )