HTMLcopy
1
<div id="container"></div>
CSScopy
8
1
html,
2
body,
3
#container {
4
width: 100%;
5
height: 100%;
6
margin: 0;
7
padding: 0;
8
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
3
// load csv data
4
anychart.data.loadCsvFile("https://gist.githubusercontent.com/awanshrestha/f234904bcc41b38dc3e6cb98ee563777/raw/c033b77d9ae698b322a6446befee4a7ed88be10e/SandP500Final.csv", function (data) {
5
6
// create a data table
7
var dataTable = anychart.data.table();
8
dataTable.addData(data);
9
10
// map the columns from the data table into the ohlc format
11
var mapping = dataTable.mapAs({
12
date: 0,
13
open: 1,
14
high: 2,
15
low: 3,
16
close: 4
17
});
18
19
// create a stock chart
20
var chart = anychart.stock();
21
22
// create the chart plot
23
var plot = chart.plot(0);
24
25
// create an ohlc series and bind it to the mapped data
26
var ohlcSeries = plot.ohlc(mapping);
27
28
// set the date/time range displayed by default
29
chart.selectRange("2021-03-01", "2023-08-20");
30
31
// set the chart title
32
chart.title("S&P 500 OHLC Chart");
33
34
// set the container id for the chart
35
chart.container("container");
36
37
// initiate the chart drawing
38
chart.draw();
39
40
});
41
42
});