-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
69 lines (66 loc) · 1.83 KB
/
main.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
$(window).on('load', function () {
fetch('/export/data.json')
.then(response => response.json())
.then(data => renderChart(data));
/**
* @param data
*/
function renderChart(data) {
data = parseData(data);
const chart = LightweightCharts.createChart(document.body, {
layout: {
backgroundColor: '#253248',
textColor: 'rgba(255, 255, 255, 0.9)',
},
grid: {
vertLines: {
color: '#334158',
},
horzLines: {
color: '#334158',
},
},
crosshair: {
mode: 1,
},
rightPriceScale: {
borderColor: '#485c7b',
mode: 1
},
timeScale: {
borderColor: '#485c7b',
}
});
const close = chart.addLineSeries({
color: 'orange'
});
close.setData(data.closeData);
const predicted = chart.addLineSeries({
color: 'aqua'
});
predicted.setData(data.predictedData);
}
/**
* @param data
* @returns {*[]}
*/
function parseData(data) {
let result = {'predictedData': [], 'closeData': []};
if (data.data) {
let predicted = data.data[0];
let close = data.data[1];
$(predicted.x).each(function (i, e) {
let time = e.replace('T00:00:00', '');
result.predictedData.push({
time: time,
value: predicted.y[i]
});
result.closeData.push({
time: time,
value: close.y[i]
});
});
}
return result;
}
});