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/csv-data/orcl-daily-short-data(2011-2016).csv',
5
function (data) {
6
// create data table on loaded data
7
var dataTable = anychart.data.table();
8
dataTable.addData(data);
9
10
// map loaded data for the ohlc series
11
var mapping = dataTable.mapAs({
12
open: 1,
13
high: 2,
14
low: 3,
15
close: 4
16
});
17
18
// map loaded data for the scroller
19
var scrollerMapping = dataTable.mapAs();
20
scrollerMapping.addField('value', 5);
21
22
// create stock chart
23
var chart = anychart.stock();
24
25
// set chart title
26
chart.title('Annotated OHLC Chart');
27
28
// set chart padding
29
chart.padding([15, 50, 57, 50]);
30
31
// create plot on the chart
32
var plot = chart.plot();
33
plot.yGrid(true).yMinorGrid(true);
34
35
var series = plot.ohlc(mapping).name('CSCO');
36
series.legendItem().iconType('rising-falling');
37
38
// create annotation
39
var annotation = plot.annotations();
40
// create line annotation
41
annotation.line({
42
// X - part of the first anchor
43
xAnchor: '2011-01-02',
44
// Y - part of the first anchor
45
valueAnchor: 11.5,
46
// X - part of the second anchor
47
secondXAnchor: '2011-08-07',
48
// Y - part of the second anchor
49
secondValueAnchor: 9,
50
stroke: '2 #DD3F2A',
51
// set hover stroke settings
52
hovered: {
53
stroke: '2 #DD3F2A'
54
}
55
});
56
// create horizontalLine annotation
57
annotation.horizontalLine({
58
// X - part of the first anchor
59
xAnchor: '2011-01-02',
60
// Y - part of the first anchor
61
valueAnchor: 16,
62
// X - part of the second anchor
63
secondXAnchor: '2016-06-12',
64
// Y - part of the second anchor
65
secondValueAnchor: 16,
66
// set stroke settings
67
stroke: {
68
thickness: 2,
69
color: '#60727B',
70
dash: '10 15'
71
},
72
// set hover stroke settings
73
hovered: {
74
stroke: {
75
thickness: 2,
76
color: '#60727B',
77
dash: '10 15'
78
}
79
}
80
});
81
// create finiteTrendChannel annotation
82
annotation.finiteTrendChannel({
83
// X - part of the first anchor
84
xAnchor: '2011-08-07',
85
// Y - part of the first anchor
86
valueAnchor: 9,
87
// X - part of the second anchor
88
secondXAnchor: '2015-01-04',
89
// Y - part of the second anchor
90
secondValueAnchor: 19,
91
// width of the trend channel
92
channelWidth: 6,
93
// set stroke settings
94
stroke: '2 #6E9C4E',
95
// set fill settings
96
fill: '#6E9C4E 0.3',
97
// set hover fill/stroke settings
98
hovered: {
99
fill: '#6E9C4E 0.2',
100
stroke: '2 #6E9C4E'
101
}
102
});
103
104
// create scroller series with mapped data
105
chart.scroller().ohlc(mapping);
106
// set container id for the chart
107
chart.container('container');
108
// initiate chart drawing
109
chart.draw();
110
111
// create range picker
112
var rangePicker = anychart.ui.rangePicker();
113
// init range picker
114
rangePicker.render(chart);
115
116
// create range selector
117
var rangeSelector = anychart.ui.rangeSelector();
118
// init range selector
119
rangeSelector.render(chart);
120
}
121
);
122
});