HTMLcopy
1
<div id="container"></div>
CSScopy
6
1
html, body, #container {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function() {
2
// The data that used in this sample can be obtained from the CDN
3
// https://cdn.anychart.com/csv-data/csco-daily.js
4
5
// create data table on loaded data
6
var dataTable = anychart.data.table();
7
dataTable.addData(get_csco_daily_data());
8
9
// map loaded data for the ohlc series
10
var mapping = dataTable.mapAs();
11
mapping.addField('open', 1, 'first');
12
mapping.addField('high', 2, 'max');
13
mapping.addField('low', 3, 'min');
14
mapping.addField('close', 4, 'last');
15
mapping.addField('value', 4, 'close');
16
17
// create stock chart
18
var chart = anychart.stock();
19
20
// create first plot on the chart
21
var plot = chart.plot(0);
22
23
// create ohlc series
24
var ohlcSeries = plot.ohlc(mapping);
25
ohlcSeries.name('CSCO');
26
27
// create second plot on the chart
28
var secondPlot = chart.plot(1);
29
secondPlot.height('25%');
30
31
// create MACD indicator fast period of 12, slow of 26 an signal of 9
32
// series types are default
33
macd_default = secondPlot.macd(mapping, 12, 26, 9);
34
35
// create third plot on the chart
36
var thirdPlot = chart.plot(2);
37
thirdPlot.height('25%');
38
39
// create MACD indicator fast period of 12, slow of 26 an signal of 9
40
// series types are all lines, even histogram
41
var macd_all_lines = thirdPlot.macd(mapping, 14, 28, 10, "line", "line", "line");
42
macd_all_lines.macdSeries().stroke('#bf360c');
43
macd_all_lines.signalSeries().stroke('#ff6d00');
44
macd_all_lines.histogramSeries().stroke('#ffe082');
45
46
// create scroller series with mapped data
47
chart.scroller().line(mapping);
48
49
// set container id for the chart
50
chart.container('container');
51
52
// initiate chart drawing
53
chart.draw();
54
});