HTMLcopy
1
<div id="container"></div>
CSScopy
7
1
html, body, #container
2
{
3
width: 100%;
4
height: 100%;
5
margin: 0;
6
padding: 0;
7
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
3
// load data
4
anychart.data.loadCsvFile("https://static.anychart.com/git-storage/word-press/data/candlestick-chart-tutorial/EUR_USDHistoricalData2year.csv", function (data) {
5
6
// create a data table
7
var dataTable = anychart.data.table(0, 'MMM d, yyyy');
8
dataTable.addData(data);
9
10
// map data
11
var mapping = dataTable.mapAs({ 'open': 2, 'high': 3, 'low': 4, 'close': 1 });
12
13
// set the chart type
14
var chart = anychart.stock();
15
16
// set the series
17
var series = chart.plot(0).candlestick(mapping);
18
series.name("EUR USD Trade Data");
19
20
// set the chart title
21
chart.title("EUR USD Historical Trade Data");
22
23
// create a plot
24
var plot = chart.plot(0);
25
// create an EMA indicator with period 20
26
var ema20 = plot.ema(mapping, 20).series();
27
// set the EMA color
28
ema20.stroke('#bf360c');
29
30
// modify the color of candlesticks making them black and white
31
series.fallingFill("black");
32
series.fallingStroke("black");
33
series.risingFill("white");
34
series.risingStroke("black");
35
36
// disable the scroller axis
37
chart.scroller().xAxis(false);
38
// map "open" values for the scroller
39
openValue = dataTable.mapAs();
40
openValue.addField('value', 2);
41
// create a scroller series with the mapped data
42
chart.scroller().column(openValue);
43
44
// set the container id
45
chart.container('container');
46
47
// draw the chart
48
chart.draw();
49
50
});
51
52
});