-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
113 lines (109 loc) · 3.27 KB
/
index.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
<!doctype html>
<html>
<head>
<title>BAY Rates</title>
<script src="https://www.chartjs.org/dist/2.7.3/Chart.bundle.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<style>
canvas {
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
}
</style>
</head>
<body>
<div style="width:90%;">
<canvas id="canvas"></canvas>
</div>
<br>
<br>
<script>
var config = {
type: 'line',
data: {
labels: [],
datasets: [{
label: 'BAY Rates',
backgroundColor: "#2da5e0",
borderColor: "#2da5e0",
data: [],
fill: false,
},{
label: 'BAY Floor',
backgroundColor: "#ed8580",
borderColor: "#ed8580",
data: [],
fill: false,
}]
},
options: {
responsive: true,
title: {
display: false,
text: 'BAY'
},
tooltips: {
mode: 'index',
intersect: false,
},
hover: {
mode: 'nearest',
intersect: true
},
scales: {
xAxes: [{
display: true,
scaleLabel: {
display: false,
labelString: 'Date'
}
}],
yAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: 'BAY-USD'
},
type: 'logarithmic',
ticks: {
userCallback: function(tick) {
var remain = tick / (Math.pow(10, Math.floor(Chart.helpers.log10(tick))));
if (remain === 1 || remain === 2 || remain === 5) {
return tick.toString();
}
return '';
}
}
}]
}
}
};
window.onload = function() {
var ctx = document.getElementById('canvas').getContext('2d');
window.myLine = new Chart(ctx, config);
$.ajax({
url: "rates1k.json",
dataType: 'json',
context: this,
success: function(resp) {
for (i = 0; i < resp.length; i++) {
let data = resp[i];
config.data.labels.push(data["BAY"]["last_updated"]);
config.data.datasets[0].data.push(data["BAY"]["price"]);
if ("floor" in data["BAY"]) {
config.data.datasets[1].data.push(data["BAY"]["floor"]);
} else {
config.data.datasets[1].data.push(0.0);
}
}
window.myLine.update();
},
error: function(xhr, status, err) {
console.error('err:', status, err);
}
});
};
</script>
</body>
</html>