-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.html
82 lines (69 loc) · 1.71 KB
/
data.html
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>chart-csv</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.10/c3.css" rel="stylesheet" type="text/css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.15/d3.min.js" charset="utf-8"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.10/c3.min.js"></script>
</head>
<body onload="run()">
<div id="graph"></div>
<script>
function parseCSV (csv) {
return csv.split('\n')
.filter(function (row) {
return !!row.trim()
})
.map(function (row) {
return row.split(',')
})
}
function haveHead (csv) {
return !/^\d+$/.test(csv[0][0])
}
function chart (id, csv) {
csv = parseCSV(csv)
var columns = []
var showLegend = haveHead(csv)
if (showLegend) {
csv.shift().forEach(function (head) {
columns.push([head])
})
} else {
for (var n = 0; n < csv[0].length; n++) {
columns.push([n])
}
}
csv.forEach(function (r) {
r.forEach(function (c, i) {
columns[i].push(parseInt(c, 10))
})
})
var opts = {
bindto: '#' + id,
data: {
columns: columns,
type: 'line'
},
point: { show: false },
axis: { x: { show: false } },
legend: { show: showLegend }
}
c3.generate(opts)
}
function run () {
chart('graph', csv)
}
var csv = `
id,timestamp,eeg1,eeg2,eeg3,eeg4,aux_left,aux_right,objects
1,1488747136,0.12,0.24,0.53,0.43,0.52,0.91,null
2,1488747136,0.12,0.24,0.53,0.43,0.52,0.91,null
3,1488747137,0.12,0.24,0.53,0.43,0.52,0.91,null
4,1488747137,0.12,0.24,0.53,0.43,0.52,0.91,null
5,1488747137,0.12,0.24,0.53,0.43,0.52,0.91,null
6,1488747137,0.12,0.24,0.53,0.43,0.52,0.91,null
`
</script>
</body>
</html>