HTMLcopy
1
<select id="typeSelect" onclick="create()">
2
<option value="default" selected disabled>Annotation Type</option>
3
<option value="andrews-pitchfork">Andrews' Pitchfork</option>
4
<option value="ellipse">Ellipse</option>
5
<option value="fibonacci-arc">Fibonacci Arc</option>
6
<option value="fibonacci-fan">Fibonacci Fan</option>
7
<option value="fibonacci-retracement">Fibonacci Retracement</option>
8
<option value="fibonacci-timezones">Fibonacci Time Zones</option>
9
<option value="horizontal-line">Horizontal Line</option>
10
<option value="infinite-line">Infinite Line</option>
11
<option value="line">Line Segment</option>
12
<option value="marker">Marker</option>
13
<option value="ray">Ray</option>
14
<option value="rectangle">Rectangle</option>
15
<option value="trend-channel">Trend Channel</option>
16
<option value="triangle">Triangle</option>
17
<option value="vertical-line">Vertical Line</option>
18
</select>
19
<button onclick="removeAll()">Remove All</button>
20
<div id="container"></div>
CSScopy
18
1
html, body {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
7
select {
8
margin: 10px 0 0 10px;
9
}
10
button {
11
margin: 10px 0 0 5px;
12
}
13
#container {
14
position: absolute;
15
width: 100%;
16
top: 35px;
17
bottom: 0;
18
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
3
// create a data table
4
var dataTable = anychart.data.table();
5
dataTable.addData([
6
['2015-12-24', 511.53, 514.98, 505.79, 506.40],
7
['2015-12-25', 512.53, 514.88, 505.69, 507.34],
8
['2015-12-26', 511.83, 514.98, 505.59, 506.23],
9
['2015-12-27', 511.22, 515.30, 505.49, 506.47],
10
['2015-12-28', 510.35, 515.72, 505.23, 505.80],
11
['2015-12-29', 510.53, 515.86, 505.38, 508.25],
12
['2015-12-30', 511.43, 515.98, 505.66, 507.45],
13
['2015-12-31', 511.50, 515.33, 505.99, 507.98],
14
['2016-01-01', 511.32, 514.29, 505.99, 506.37],
15
['2016-01-02', 511.70, 514.87, 506.18, 506.75],
16
['2016-01-03', 512.30, 514.78, 505.87, 508.67],
17
['2016-01-04', 512.50, 514.77, 505.83, 508.35],
18
['2016-01-05', 511.53, 516.18, 505.91, 509.42],
19
['2016-01-06', 511.13, 516.01, 506.00, 509.26],
20
['2016-01-07', 510.93, 516.07, 506.00, 510.99],
21
['2016-01-08', 510.88, 515.93, 505.22, 509.95],
22
['2016-01-09', 509.12, 515.97, 505.15, 510.12],
23
['2016-01-10', 508.53, 516.13, 505.66, 510.42],
24
['2016-01-11', 508.90, 516.24, 505.73, 510.40]
25
]);
26
27
// map the data
28
mapping = dataTable.mapAs();
29
mapping.addField('open', 1, 'first');
30
mapping.addField('high', 2, 'max');
31
mapping.addField('low', 3, 'min');
32
mapping.addField('close', 4, 'last');
33
mapping.addField('value', 4, 'last');
34
35
// create a stock chart
36
chart = anychart.stock();
37
38
// create an OHLC series
39
var ohlcSeries = chart.plot(0).ohlc(mapping);
40
ohlcSeries.name("Series 1")
41
42
// create a line series
43
var lineSeries = chart.plot(1).line(mapping);
44
lineSeries.name("Series 2")
45
46
// allow drawing on the first plot
47
chart.plot(0).annotations().enabled(true);
48
49
// forbid drawing on the second plot
50
chart.plot(1).annotations().enabled(false);
51
52
// set the chart title
53
chart.title("Forbidding Drawing");
54
55
// set the container id
56
chart.container("container");
57
58
// initiate drawing the chart
59
chart.draw();
60
61
// reset the select list to the first option
62
chart.listen("annotationDrawingFinish", function(){
63
document.getElementById("typeSelect").value = "default";
64
});
65
});
66
67
// create annotations
68
function create() {
69
var select = document.getElementById("typeSelect");
70
chart.annotations().startDrawing(select.value);
71
}
72
73
// remove all annotations
74
function removeAll() {
75
chart.annotations().removeAllAnnotations();
76
}