-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
232 lines (202 loc) · 4.99 KB
/
test.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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="test.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.0/jquery.min.js"></script>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<script>
//put graph generation code here
//On load function, get our data and do any setup required
$(document).ready(function() {
//sample data, real data will be loaded from database
data = [
{
'time': 0,
'current': 1285.76,
'rpm': 7200,
'duty': 10,
'voltage': 6000.56
},
{
'time': 1,
'current': 1685.76,
'rpm': 7400,
'duty': 20,
'voltage': 6060.59
},
{
'time': 2,
'current': 1285.76,
'rpm': 7200,
'duty': 30,
'voltage': 6000.56
},
{
'time': 3,
'current': 1285.76,
'rpm': 7200,
'duty': 40,
'voltage': 6000.56
},
{
'time': 4,
'current': 1285.76,
'rpm': 7200,
'duty': 50,
'voltage': 6000.56
},
{
'time': 5,
'current': 1285.76,
'rpm': 7200,
'duty': 60,
'voltage': 6000.56
},
{
'time': 6,
'current': 1285.76,
'rpm': 7200,
'duty': 70,
'voltage': 6000.56
},
{
'time': 7,
'current': 1285.76,
'rpm': 7200,
'duty': 80,
'voltage': 6000.56
},
{
'time': 8,
'current': 1285.76,
'rpm': 7200,
'duty': 90,
'voltage': 6000.56
},
{
'time': 9,
'current': 1285.76,
'rpm': 7200,
'duty': 100,
'voltage': 6000.56
}]
var dataIncluded = [];
Object.keys(data[0]).map(key => {
if (key !== 'time')
dataIncluded.push(key);
})
//generate data for chart ** NOT IN FUNCTION ** WE ONLY WANT TO DO THIS ONCE
var newData = [];
var axisY = [];
for(var i in dataIncluded) {
newData.push({
type:"line",
name: dataIncluded[i],
showInLegend: true,
markerSize: 0,
axisYIndex: parseInt(i),
dataPoints: []
})
axisY.push({
title: dataIncluded[i]
})
}
// newData[k-1] matches k key:value pair of data[j]
// Essentially bruteforcing it use for another data structure here?
for(var j in data) {
//console.log("j" + j);
Object.keys(data[j]).map((key,k) => {
//console.log({x:data[j]['time'], y:data[j][key]});
if (k !== 0){
newData[k-1].dataPoints.push({x:data[j]['time'], y:data[j][key]})
}
})
}
generateChart([]);
// chart.options.data[0].visible = false;
//chart.render();
//DONE
//
//
// FUNCTIONS
//
//
// Generates chart
function generateChart(selected) {
var chart = new CanvasJS.Chart("chartContainer", {
title: {
text: "Your e-Foil"
},
axisX: {
title: "Time",
suffix: "s"
},
axisY: axisY,
toolTip: {
shared: true
},
legend: {
cursor: "pointer",
verticalAlign: "top",
horizontalAlign: "center",
dockInsidePlotArea: true
},
data: newData
});
// check if selected has values - initially empty
if (selected.length > 0){
for (var i in dataIncluded){
if (!selected.includes(dataIncluded[i])){ //if checked in checkbox
chart.options.data[i].visible = false;
} else {
chart.options.data[i].visible = true;
}
}
}
chart.render()
}
// Determines which data has been selected for viewing -> () => array
function displayData() {
var selectedData = [];
$(".form-check-input").each(function() {
if($(this).is(":checked")){
selectedData.push($(this).val())
}
})
return selectedData;
}
// Runs when the generate button is clicked. Calls generateChart with the selected elements
$("#generateButton").click(function() {
var selected = displayData()
console.log(selected);
generateChart(selected);
})
})
</script>
</head>
<body>
<div class="wrapper">
<div id="selectContainer">
<div class="form-check">
<input class="form-check-input" type="checkbox" value="current">
<label class="form-check-label" for="1">current</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="rpm">
<label class="form-check-label" for="2">rpm</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="duty">
<label class="form-check-label" for="3">duty</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="voltage">
<label class="form-check-label" for="4">voltage</label>
</div>
<div><button type="submit" id="generateButton">Generate</button></div>
</div>
<div id="chartContainer" style="height: 300px; width: 100%;"></div>
</div>
</body>
</html>