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
<button onclick="copy()">Copy to the Second Plot</button>
21
<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
// the data used in this sample can be obtained from the CDN
4
// https://cdn.anychart.com/csv-data/csco-daily.js
5
// create a data table using this data
6
var dataTable = anychart.data.table();
7
dataTable.addData(get_csco_daily_short_data());
8
9
// map the data
10
var mapping = dataTable.mapAs({"value": 4});
11
12
// create a stock chart
13
chart = anychart.stock();
14
15
// create a line series
16
var series1 = chart.plot(0).line(mapping);
17
series1.name("Series 1")
18
19
// create an area series
20
var series2 = chart.plot(1).area(mapping);
21
series2.name("Series 2")
22
23
// create an Ellipse annotation
24
chart.plot(0).annotations().ellipse({
25
xAnchor: "2006-11-20",
26
valueAnchor: 35.41,
27
secondXAnchor: "2007-02-24",
28
secondValueAnchor: 18.05,
29
});
30
31
// create a Rectangle annotation
32
chart.plot(0).annotations().rectangle({
33
xAnchor: "2007-06-01",
34
valueAnchor: 35.41,
35
secondXAnchor: "2007-12-09",
36
secondValueAnchor: 18.05
37
});
38
39
// set the chart title
40
chart.title("Serializing and Deserializing (JSON)");
41
42
// set the container id
43
chart.container("container");
44
45
// initiate drawing the chart
46
chart.draw();
47
48
// reset the select list to the first option
49
chart.listen("annotationDrawingFinish", function(){
50
document.getElementById("typeSelect").value = "default";
51
});
52
});
53
54
// create annotations
55
function create() {
56
var select = document.getElementById("typeSelect");
57
chart.plot(0).annotations().startDrawing(select.value);
58
}
59
60
// remove all annotations
61
function removeAll() {
62
chart.plot(0).annotations().removeAllAnnotations();
63
}
64
65
// copy annotations to the second plot
66
function copy() {
67
// serialize annotations from the first plot
68
var json = chart.plot(0).annotations().toJson();
69
// deserialize the annotations to the second plot
70
chart.plot(1).annotations().fromJson(json);
71
}