-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
66 lines (54 loc) · 1.5 KB
/
sketch.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
const ctx = document.getElementById('myChart');
const dolar_dias = "https://economia.awesomeapi.com.br/json/daily/USD-BRL/5";
const btc_dias = "https://economia.awesomeapi.com.br/json/daily/BTC-BRL/5";
const eur_dias = "https://economia.awesomeapi.com.br/json/daily/EUR-BRL/5";
var values = [];
var day = 0;
function recuperar_dias(coin_day) {
fetch(coin_day)
.then(resposta => {
return resposta.json();
})
.then(data => {
day = data[0].create_date;
/*
day = day.split(" ");
day = day[0].split("-");
day = day[2];
*/
day = day.split(" ")[0].split("-")[2];
console.log(day);
for (var v = 0; v < data.length; v++) {
values[v] = data[v].high;
values[v] = parseFloat(values[v]);
values[v] = values[v].toFixed(2);
}
console.log(values);
})
}
window.addEventListener("load", () => {
recuperar_dias(dolar_dias);
reload();
});
function reload() {
setTimeout(() => {
chart = new Chart(ctx, {
type: 'line',
data: {
labels: [day - 4, day - 3, day - 2, day - 1, day],
datasets: [{
label: 'coins value truoght the last 5 days',
data: [values[4], values[3], values[2], values[1], values[0]],
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: false
}
}
}
});
}, 1000);
}