forked from karthik947/TradingviewChartCSVFile
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
38 lines (34 loc) · 938 Bytes
/
index.js
File metadata and controls
38 lines (34 loc) · 938 Bytes
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
const getData = async () => {
const res = await fetch('data.csv');
const resp = await res.text();
// console.log(resp);
const cdata = resp.split('\n').map((row) => {
const [time1, time2, open, high, low, close] = row.split(',');
return {
time: new Date(`${time1}, ${time2}`).getTime() / 1000,
open: open * 1,
high: high * 1,
low: low * 1,
close: close * 1,
};
});
return cdata;
// console.log(cdata);
};
// getData();
const displayChart = async () => {
const chartProperties = {
width: 1500,
height: 600,
timeScale: {
timeVisible: true,
secondsVisible: true,
},
};
const domElement = document.getElementById('tvchart');
const chart = LightweightCharts.createChart(domElement, chartProperties);
const candleseries = chart.addCandlestickSeries();
const klinedata = await getData();
candleseries.setData(klinedata);
};
displayChart();