HTMLcopy
1
<div id="container">
2
<div class="container-title">
3
<p>
4
See also
5
<a href="https://www.anychart.com/products/anystock/drawing_tools/" target="_blank">Drawing Tools and
6
Annotations Demo</a>
7
</p>
8
</div>
9
</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
anychart.data.loadCsvFile(
3
// The data used in this sample can be obtained from the CDN
4
// https://cdn.anychart.com/samples-data/stock-annotations/vertical-range-annotation/data.csv
5
'https://cdn.anychart.com/samples-data/stock-annotations/vertical-range-annotation/data.csv',
6
function (data) {
7
// create data table on loaded data
8
var dataTable = anychart.data.table();
9
dataTable.addData(data);
10
11
// map loaded data for the candlestick series
12
var mapping = dataTable.mapAs({
13
open: 1,
14
high: 2,
15
low: 3,
16
close: 4,
17
value: 5
18
});
19
20
// create stock chart
21
var chart = anychart.stock();
22
23
// set chart's title
24
chart.title('The Nastiest Bear Market in the 20th Century');
25
26
// create plot on the chart
27
var plot = chart.plot(0);
28
plot.yGrid(true).yMinorGrid(true);
29
30
// create candlestick series
31
var series = plot.candlestick(mapping).name('S&P 500');
32
series.legendItem().iconType('rising-falling');
33
34
// create MACD indicator on the second plot
35
var indicatorPlot = chart.plot(1);
36
indicatorPlot.macd(mapping);
37
38
// create vertical range annotation on the both plots
39
plot
40
.annotations()
41
.verticalRange({
42
xAnchor: '2007-10-09',
43
secondXAnchor: '2009-03-09'
44
})
45
.allowEdit(false); // disable edit mode
46
47
indicatorPlot
48
.annotations()
49
.verticalRange({
50
xAnchor: '2007-10-09',
51
secondXAnchor: '2009-03-09'
52
})
53
.allowEdit(false); // disable edit mode
54
55
// create scroller series with mapped data
56
chart.scroller().area(mapping);
57
58
// set chart selected date/time range
59
chart.selectRange('2005-01-01', '2010-01-01');
60
61
// set container id for the chart
62
chart.container('container');
63
// initiate chart drawing
64
chart.draw();
65
66
// create range picker
67
var rangePicker = anychart.ui.rangePicker();
68
// init range picker
69
rangePicker.render(chart);
70
71
// create range selector
72
var rangeSelector = anychart.ui.rangeSelector();
73
// init range selector
74
rangeSelector.render(chart);
75
}
76
);
77
});