-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchart.js
More file actions
44 lines (37 loc) · 981 Bytes
/
Copy pathchart.js
File metadata and controls
44 lines (37 loc) · 981 Bytes
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
// let params = new URLSearchParams(document.location.search);
// let coin_name = params.get("coin");
// function coin_url() {
// return `https://api.coincap.io/v2/assets/bitcoin/history?interval=d1`;
// }
async function get_coin() {
// let url = coin_url(coin_name);
let respons = await fetch('https://api.coincap.io/v2/assets/bitcoin/history?interval=d1');
let json = await respons.json();
let data = json.data;
let yValues = [];
let xValues = [];
data.forEach((item) => {
yValues.push(item.priceUsd);
xValues.push(item.time);
});
return {
x: xValues,
y: yValues,
};
}
get_coin().then(function (values) {
new Chart("myChart", {
type: "line",
data: {
labels: values.x,
datasets: [
{
backgroundColor: "rgba(238,130,238,0.5)",
borderColor: "rgba(255,0,0,1)",
data: values.y,
},
],
},
options: { yValues: values.y },
});
});