-
Notifications
You must be signed in to change notification settings - Fork 1
/
chart2.js
59 lines (48 loc) · 2.1 KB
/
chart2.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
$(document).ready(function() {
function getData() {
var url ="https://api.thingspeak.com/channels/2195036/fields/5,6.json?api_key=DG5Q1OBE0MW2GDTF&results=5";
$.getJSON(url, function(data) {
var field5Values = [];
var field6Values = [];
var timestamps = [];
$.each(data.feeds, function(index, feed) {
field5Values.push(feed.field5);
field6Values.push(feed.field6);
timestamps.push(feed.created_at);
});
//dealing the the graph
var ctx = document.getElementById('myChart2').getContext('2d');
var chart = new Chart(ctx, {
type:'bar',
data:{
labels:timestamps,
datasets:[{
label: 'SpaceData1%',
data: field5Values,
backgroundColor: red(0.2),
borderColor: red(1),
borderWidth: 1
},
{
label: 'SpaceData2%',
data: field6Values,
backgroundColor: blue(0.2),
borderColor: blue(1),
borderWidth: 1
}
]
},
options: {
scales: {
yAxes: [{
thicks: {
beginAtZero: true
}
}]
}
}
});
});
}
getData();
});