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
// The data that have been used for this sample can be taken from the CDN
3
// https://cdn.anychart.com/csv-data/ibm-daily-short.js
4
// https://cdn.anychart.com/csv-data/empty_data(2009-2010).js
5
6
// create data tables on loaded data
7
var ibmDataTable = anychart.data.table();
8
ibmDataTable.addData(get_ibm_daily_short_data()); // eslint-disable-line no-undef
9
ibmDataTable.addData(get_empty_data()); // eslint-disable-line no-undef
10
11
// create stock chart
12
var chart = anychart.stock();
13
14
// set chart title
15
chart.title('Annotated Step Line Chart');
16
17
// set chart padding
18
chart.padding([15, 50, 57, 50]);
19
20
// create plot
21
var plot = chart.plot();
22
23
// create step line series with mapped data on the plot
24
var ibm = plot.stepLine(
25
ibmDataTable.mapAs({
26
value: 4
27
})
28
);
29
ibm.name('IBM');
30
ibm.tooltip().format(function () {
31
var value = this.value;
32
if (isNaN(this.value)) {
33
value = 'undefined';
34
}
35
return this.seriesName + ': ' + value;
36
});
37
38
// create annotation
39
var annotation = plot.annotations();
40
// create annotation line
41
annotation.line({
42
// X - part of the first anchor
43
xAnchor: '2008-01-06',
44
// Y - part of the first anchor
45
valueAnchor: 97.67,
46
// X - part of the second anchor
47
secondXAnchor: '2008-07-13',
48
// Y - part of the second anchor
49
secondValueAnchor: 129.89,
50
stroke: {
51
thickness: 2,
52
color: '#60727B',
53
dash: '10 15'
54
},
55
hovered: {
56
stroke: {
57
thickness: 2,
58
color: '#60727B',
59
dash: '10 15'
60
}
61
}
62
});
63
// create annotation line
64
annotation.line({
65
// X - part of the first anchor
66
xAnchor: '2008-07-13',
67
// Y - part of the first anchor
68
valueAnchor: 129.89,
69
// X - part of the second anchor
70
secondXAnchor: '2008-11-16',
71
// Y - part of the second anchor
72
secondValueAnchor: 74.88,
73
// set stroke settings
74
stroke: {
75
thickness: 2,
76
color: '#60727B',
77
dash: '10 15'
78
},
79
hovered: {
80
stroke: {
81
thickness: 2,
82
color: '#60727B',
83
dash: '10 15'
84
}
85
}
86
});
87
// create fibonacci Retracement
88
annotation.fibonacciRetracement({
89
// X - part of the first anchor
90
xAnchor: '2008-07-13',
91
// Y - part of the first anchor
92
valueAnchor: 135,
93
// X - part of the second anchor
94
secondXAnchor: '2008-07-13',
95
// Y - part of the second anchor
96
secondValueAnchor: 74.88,
97
// set stroke settings
98
stroke: '2 #60727B',
99
hovered: {
100
stroke: '2 #6E9C4E 0.75'
101
}
102
});
103
104
// create scroller series with mapped data
105
chart.scroller().line(
106
ibmDataTable.mapAs({
107
value: 4
108
})
109
);
110
// set chart selected date/time range
111
chart.selectRange('2008-01-06', '2010-06-20');
112
// set container id for the chart
113
chart.container('container');
114
// initiate chart drawing
115
chart.draw();
116
117
// create range picker
118
var rangePicker = anychart.ui.rangePicker();
119
// init range picker
120
rangePicker.render(chart);
121
122
// create range selector
123
var rangeSelector = anychart.ui.rangeSelector();
124
// init range selector
125
rangeSelector.render(chart);
126
});