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
var dataTable = anychart.data.table();
3
dataTable.addData(get_dji_daily_short_data());
4
5
var mapping = dataTable.mapAs({value: 1});
6
7
var chart = anychart.stock();
8
chart.padding(10, 10, 10, 50);
9
10
var firstPlot = chart.plot(0);
11
firstPlot.line(mapping);
12
firstPlot.annotations([{
13
type: "rectangle",
14
xAnchor: 1107129600000,
15
valueAnchor: 9000,
16
secondXAnchor: 1131408000000,
17
secondValueAnchor: 12000,
18
fill: "#4CAF50 0.5",
19
stroke: "3 #FF9800"
20
}]);
21
22
var secondPlot = chart.plot(1);
23
secondPlot.area(mapping);
24
secondPlot.annotations([{
25
type: "ellipse",
26
xAnchor: 1167782400000,
27
valueAnchor: 11000,
28
secondXAnchor: 1199232000000,
29
secondValueAnchor: 14500,
30
fill: "#4CAF50 0.5",
31
stroke: "3 #FF9800"
32
}]);
33
34
chart.container("container");
35
chart.draw();
36
37
var selectAnnotation = firstPlot.annotations();
38
39
var annotation = chart.annotations();
40
annotation.select(selectAnnotation.getAnnotationAt(0));
41
42
// Get selected annotation.
43
var selectedAnnotation = annotation.getSelectedAnnotation();
44
45
var type = selectedAnnotation.getType();
46
47
chart.title("Get selected annotation and get type - " + type + ".");
48
});