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 used in this sample can be obtained from the CDN
3
// https://cdn.anychart.com/csv-data/csco-daily.csv
4
anychart.data.loadCsvFile('https://cdn.anychart.com/csv-data/csco-daily.csv', function (data) {
5
// create data table on loaded data
6
var dataTable = anychart.data.table();
7
dataTable.addData(data);
8
9
// map loaded data for the ohlc series
10
var mapping = dataTable.mapAs({'open': 1, 'high': 2, 'low': 3, 'close': 4});
11
12
// map loaded data for the scroller
13
var scrollerMapping = dataTable.mapAs();
14
scrollerMapping.addField('value', 5);
15
16
// create stock chart
17
var chart = anychart.stock();
18
// set chart padding
19
chart.padding([75, 50, 57, 50]);
20
21
// create first plot on the chart
22
var plot = chart.plot(0);
23
// grid settings
24
plot.yGrid(true)
25
.xGrid(true)
26
.xMinorGrid(true)
27
.yMinorGrid(true);
28
29
// create EMA indicators with period 50
30
var ema = plot.ema(dataTable.mapAs({'value': 4}));
31
ema.series().stroke('1.5 Red');
32
33
// create EMA indicators with period 50
34
var ema = plot.ema(dataTable.mapAs({'value': 7}));
35
ema.series().stroke('2 Black');
36
37
// create candlestick series
38
var series = plot.candlestick(mapping).name('CSCO');
39
series.legendItem().iconType('rising-falling');
40
41
// create annotation
42
var annotation = plot.annotations();
43
44
// create first marker annotation and set settings
45
annotation.marker()
46
.xAnchor(954090366593)
47
.valueAnchor(85)
48
.stroke('2 #F44336')
49
.markerType('arrow-down')
50
.allowEdit(false);
51
52
// create second marker annotation and set settings
53
annotation.marker()
54
.xAnchor(959108502857)
55
.valueAnchor(49.1)
56
.fill('green 0.5')
57
.stroke('2 green 0.75')
58
.allowEdit(false);
59
60
// create first label annotation and set settings
61
annotation.label()
62
.xAnchor(954090366593)
63
.valueAnchor(85)
64
.anchor('right-top')
65
.offsetX(20)
66
.offsetY(-4)
67
.padding(6)
68
.text('SELL')
69
.fontColor('#fff')
70
.background({
71
fill: 'red 0.75',
72
stroke: '0.5 #455a64',
73
corners: 7
74
})
75
.allowEdit(false);
76
77
// create second label annotation and set settings
78
annotation.label()
79
.xAnchor(959108502857)
80
.valueAnchor(49.1)
81
.anchor('left-bottom')
82
.offsetX(20)
83
.offsetY(-23)
84
.padding(6)
85
.text('Time to B')
86
.fontColor('#fff')
87
.background({
88
fill: 'green 0.75',
89
stroke: '1 #455a64',
90
corners: 7
91
})
92
.allowEdit(false);
93
94
// create scroller series with mapped data
95
chart.scroller().candlestick(mapping);
96
97
// set chart selected date/time range
98
chart.selectRange('1999-10-25', '2000-10-11');
99
100
// set container id for the chart
101
chart.container('container');
102
// initiate chart drawing
103
chart.draw();
104
105
// create range picker
106
var rangePicker = anychart.ui.rangePicker();
107
// init range picker
108
rangePicker.render(chart);
109
110
// create range selector
111
var rangeSelector = anychart.ui.rangeSelector();
112
// init range selector
113
rangeSelector.render(chart);
114
});
115
});