-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_chart.js
47 lines (44 loc) · 1.08 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
const { ChartJSNodeCanvas } = require("chartjs-node-canvas");
//https://github.com/Automattic/node-canvas/issues/1893#issuecomment-1096988007
async function create_price_graph(ohlcv_list) {
ohlcv_list = ohlcv_list.slice(-7);
const chartJSNodeCanvas = new ChartJSNodeCanvas({
width: 650,
height: 420,
backgroundColour: "white"
});
let data = [];
let labels = [];
for (let i=0; i < ohlcv_list.length; i++) {
let ohlcv_day = ohlcv_list[i];
for (let j=0; j < 4; j++) {
data.push({ x: i*4+j, y: ohlcv_day[j+1] });
labels.push(" ");
}
}
const config = {
type: "line",
data: {
datasets: [{
data: data,
label: "Astral Credits Price (Last 7 Days)"
}],
labels: labels
},
options: {
scales: {
y: {
ticks: {
callback: function(value, index, ticks) {
return '$'+String(value).slice(0, 8);
}
}
}
}
}
};
return await chartJSNodeCanvas.renderToBuffer(config);
}
module.exports = {
create_price_graph: create_price_graph
};