forked from AronVanAmmers/curve-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chart.js
74 lines (68 loc) · 1.88 KB
/
chart.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
67
68
69
70
71
72
73
74
var chart_options = {
chart: {
height: 300,
type: 'line',
stacked: false,
zoom: {
type: 'x',
enabled: true,
autoScaleYaxis: true
},
toolbar: {autoSelected: 'zoom'}
},
markers: {size: 0},
colors: ['#000050'],
stroke: {width: 2},
xaxis: {
type: 'datetime'
},
yaxis: {
title: {text: 'Profit [%]'},
labels: {
tooltip: {enabled: true},
formatter: function (val) {
return (Math.floor(val * 100) / 100).toFixed(2);
}
}
},
tooltip: {
shared: false,
y: {
formatter: function (val) {
return Math.floor(val * 100000) / 100000 + '%';
}
}
},
series: [{
name: 'Virtual growth of liquidity share',
data: []
}]
}
function init_chart() {
var options = chart_options;
$.getJSON('stats.json', function(json) {
var apr = json['apr'];
var daily_apr = json['daily_apr'];
var weekly_apr = json['weekly_apr'];
var data = json['data']
$('#apr-profit').text((apr * 100).toFixed(2));
$('#daily-apr').text((daily_apr * 100).toFixed(2));
$('#weekly-apr').text((weekly_apr * 100).toFixed(2));
var step_size = Math.max(Math.round(data.length / 500), 1);
var start_profit = data[0][1]
for (let i = 0; i < data.length; i++) {
if ((i % step_size == 0) | (i == data.length - 1)) {
var el = data[i];
options.series[0].data.push({
x: new Date(el[0] * 1000),
y: (el[1] / start_profit - 1) * 100
});
}
}
var chart = new ApexCharts(
document.querySelector("#chart"),
options
);
chart.render();
});
}