-
Notifications
You must be signed in to change notification settings - Fork 0
/
chart.html
67 lines (61 loc) · 2.68 KB
/
chart.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body>
<div>
<canvas id="myChart" width="200" height="80"></canvas>
</div>
<script>
let a = ()=>{
fetch('https://api.coingecko.com/api/v3/coins/bitcoin/market_chart?vs_currency=usd&days=1&interval=hourly')
.then(response => response.json())
.then(data => {
for (let i = 0; i < data['prices'].length; i++) {
console.log(data['prices'][i][1].toFixed(2)+ " USD")
}
})
.catch(err => alert("error"))
}
let b = ()=>{
let time = new Date(Date.now() - (3600*24*1000));
let hour = time.getHours();
let arr=[];
for (let i = 0; i < 24; i++) {
if(hour>=23){
hour=0;
}
else
hour++;
arr+=hour;
}
}
const ctx = document.getElementById('myChart');
const myChart = new Chart(ctx, {
type: 'line',
data: {
labels: ['1am', '2am', '3am', '4am', '5am', '6am', '7am', '8am', '9am', '10am', '11am', '12am', '1pm', '2pm', '3pm', '4pm', '5pm', '6pm', '7pm', '8pm', '9pm', '10pm', '11pm', '12pm'],
datasets: [{
label: 'Bitcoin price',
data: [[1660831328221,23498.056141562774],[1660834820925,23428.465875440546],[1660838500790,23472.0421571502],[1660842058440,23325.598731776125],[1660845661210,23283.007167550375],[1660849261302,23291.529651682322],[1660852910107,23378.33032470008],[1660856407217,23425.86439909843],[1660860095968,23400.33134198729],[1660863636049,23376.62638464841],[1660867260920,23248.38422819264],[1660870816274,22952.662241228776],[1660874596707,22759.970477278788],[1660878077867,22795.071341747593],[1660881745914,22802.802043420696],[1660885308508,22815.618135165514],[1660888847364,22835.792879012177],[1660892538578,22056.33340239971],[1660896083518,21946.143131590514],[1660899618042,21864.06851809551],[1660903245863,21776.1758117956],[1660906924829,21662.04624144007],[1660910445396,21389.42813617057],[1660914128294,21490.127084404678],[1660917278000,21485.07026259155]],
borderWidth: 2,
borderColor : 'red',
backgroundColor : 'yellow'
}]
},
options: {
scales: {
y: {
beginAtZero: false
}
}
}
});
</script>
</body>
</html>