-
Notifications
You must be signed in to change notification settings - Fork 0
/
d3_1day.js
108 lines (83 loc) · 2.38 KB
/
d3_1day.js
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**
* Created by skaymen on 6/12/2017.
*/
"use strict";
d3.json("1day.json", function(err,data) {
console.log("data length: ",data.length);
var times = ["time"];
var values = ["discharge"];
//for holding x and y axis values, respectively. In C3, the first value in the list
//of data is the "title" of that set of data
for (var i=0; i<data.length; i++) {
times.push(data[i]["dateTime"].slice(11,19));
//take only the time (since we are only using 1 day of data
values.push(data[i]["value"]);
//fill data for y axis
}
var chart = c3.generate({
//generate chart using c3
bindto: '#chart',
//bind to char div
data: {
type: "spline",
//this type of chart has curvier lines
selection: {
draggable: true
},
//make it draggable
xFormat: '%H:%M:%S',
//format time
x: "time",
//select value for x axis
columns: [
times,values
],
colors: {
// discharge: '#ff0000'
}
},
axis : {
//set up x axis
x : {
type : 'timeseries',
tick: {
format: '%H:%M:%S'
//format: '%Y' // format string is also available for timeseries data
},
label: {
text: "Time",
position: "outer-center"
//set and position x label
}
},
y: {
label: {
text: "cubic feet per second",
position: "outer-middle"
//set and position y label
}
}
},
//enable zoom
// zoom: {
// enabled: true
// },
//turn on the subchart
subchart: {
show: true
}
});
// test out different transformations
setTimeout(function () {
chart.transform('scatter');
}, 2000);
setTimeout(function () {
chart.transform('area-spline');
}, 4000);
setTimeout(function () {
chart.transform('bar', 'discharge');
}, 6000);
setTimeout(function () {
chart.transform('spline', 'discharge');
}, 8000);
});