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/orcl-daily-short.js
4
// https://cdn.anychart.com/csv-data/csco-daily-short.js
5
// https://cdn.anychart.com/csv-data/empty_data(2009-2010).js
6
7
// create data tables on loaded data
8
var orclDataTable = anychart.data.table();
9
orclDataTable.addData(get_orcl_daily_short_data()); // eslint-disable-line no-undef
10
11
var cscoDataTable = anychart.data.table();
12
cscoDataTable.addData(get_csco_daily_short_data()); // eslint-disable-line no-undef
13
14
var emptyDataTable = anychart.data.table();
15
emptyDataTable.addData(get_empty_data()); // eslint-disable-line no-undef
16
17
// create stock chart
18
var chart = anychart.stock();
19
20
// set chart title
21
chart.title('Annotated Combination of OHLC Chart and Line Chart');
22
23
// set chart padding
24
chart.padding([15, 50, 57, 50]);
25
26
chart.tooltip().useHtml(true);
27
28
// create plot
29
var plot = chart.plot();
30
// set grid settings
31
plot.yGrid(true).xGrid(true).yMinorGrid(true).xMinorGrid(true);
32
33
plot.legend().itemsFormatter(function (items) {
34
items.splice(2, 1);
35
// return items array
36
return items;
37
});
38
39
// create step line series with mapped data on the plot
40
var ORCL = plot
41
.ohlc(
42
orclDataTable.mapAs({
43
open: 1,
44
high: 2,
45
low: 3,
46
close: 4
47
})
48
)
49
.name('ORCL');
50
ORCL.tooltip().format(function () {
51
if (this.open === 0 && isNaN(this.close)) {
52
return (
53
'<span>' +
54
this.seriesName +
55
'</span><br/>' +
56
'<span style="color: #ccc">Open</span>: undefined' +
57
'<br/><span style="color: #ccc">High</span>: undefined' +
58
'<br/><span style="color: #ccc">Low</span>: undefined' +
59
'<br/><span style="color: #ccc">Close</span>: undefined<br/><br/>'
60
);
61
}
62
return (
63
'<span>' +
64
this.seriesName +
65
'</span><br/>' +
66
'<span style="color: #ccc">Open</span>: ' +
67
this.open +
68
'<br/><span style="color: #ccc">High</span>: ' +
69
this.high +
70
'<br/><span style="color: #ccc">Low</span>: ' +
71
this.low +
72
'<br/><span style="color: #ccc">Close</span>: ' +
73
this.close +
74
'<br/><br/>'
75
);
76
});
77
78
// create step line series with mapped data on the plot
79
var csco = plot
80
.line(
81
cscoDataTable.mapAs({
82
value: 4
83
})
84
)
85
.name('CSCO');
86
csco.tooltip().format(function () {
87
var value = this.value;
88
if (isNaN(this.value)) {
89
value = 'undefined';
90
}
91
return this.seriesName + ': ' + value;
92
});
93
94
// create plot empty series with mapped data
95
plot
96
.line()
97
.data(
98
emptyDataTable.mapAs({
99
value: 1
100
})
101
)
102
.stroke('none')
103
.tooltip(false);
104
105
// create annotation
106
var annotation = plot.annotations();
107
// create annotation fibonacci Arc
108
annotation
109
.fibonacciArc({
110
// X - part of the first anchor
111
xAnchor: '2007-12-23',
112
// Y - part of the first anchor
113
valueAnchor: 23.31,
114
// X - part of the second anchor
115
secondXAnchor: '2008-04-20',
116
// Y - part of the second anchor
117
secondValueAnchor: 22.28,
118
// set stroke settings
119
stroke: '1.5 #76BF72'
120
// disable interaction with Annotation
121
})
122
.allowEdit(false);
123
// create annotation fibonacci Fan
124
annotation
125
.fibonacciFan({
126
// X - part of the first anchor
127
xAnchor: '2009-03-08',
128
// Y - part of the first anchor
129
valueAnchor: 13.8,
130
// X - part of the second anchor
131
secondXAnchor: '2009-06-28',
132
// Y - part of the second anchor
133
secondValueAnchor: 22,
134
// set levels
135
levels: [0, 0.57, 0.87, 1],
136
// set time levels
137
timeLevels: [0, 1],
138
// set stroke settings
139
stroke: '1.5 #FA8072'
140
// disable interaction with Annotation
141
})
142
.allowEdit(false);
143
144
// set chart selected date/time range
145
chart.selectRange('2007-08-05', '2010-06-20');
146
// set container id for the chart
147
chart.container('container');
148
// initiate chart drawing
149
chart.draw();
150
151
// create range picker
152
var rangePicker = anychart.ui.rangePicker();
153
// init range picker
154
rangePicker.render(chart);
155
156
// create range selector
157
var rangeSelector = anychart.ui.rangeSelector();
158
// init range selector
159
rangeSelector.render(chart);
160
});