HTMLcopy
1
<label for="seriesSelect">Series: </label>
2
<select id="seriesSelect" onchange="setPosition()">
3
<option value="0">Series 1</option>
4
<option value="1">Series 2</option>
5
</select>
6
<label for="positionSelect">Position: </label>
7
<select id="positionSelect" onchange="setPosition()">
8
<option value="series">series</option>
9
<option value="series-negative">series-negative</option>
10
<option value="series-positive">series-positive</option>
11
<option value="zero">zero</option>
12
</select>
13
<div id="container"></div>
CSScopy
16
1
html, body {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
7
label {
8
display: inline-block;
9
margin: 10px 0 0 10px;
10
}
11
#container {
12
position: absolute;
13
width: 100%;
14
top: 35px;
15
bottom: 0;
16
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
3
// create data
4
dataTable = anychart.data.table();
5
dataTable.addData([
6
["2015-12-24", 5.3, -4.0],
7
["2015-12-25", 9.9, -8.9],
8
["2015-12-26", 1.1, -1.7],
9
["2015-12-27", 7.1, -4.3],
10
["2015-12-28", 4.4, -6.5],
11
["2015-12-29", 6.5, -5.3],
12
["2015-12-30", 2.0, -2.8],
13
["2015-12-31", 5.3, -7.4],
14
["2016-01-01", 8.7, -6.5],
15
["2016-01-02", 3.1, -2.3],
16
["2016-01-03", 0.0, 0.0],
17
["2016-01-04", -8.8, 0.6],
18
["2016-01-05", -2.0, 1.8],
19
["2016-01-06", -4.4, 3.0],
20
["2016-01-07", -9.4, 9.4],
21
["2016-01-08", -6.6, 7.9],
22
["2016-01-09", -6.8, 5.0],
23
["2016-01-10", -5.0, 6.1],
24
["2016-01-11", -4.2, 9.5],
25
["2016-01-12", -7.9, 4.9],
26
["2016-01-13", -10.1, 9.1]
27
]);
28
29
// map the data
30
var mapping_1 = dataTable.mapAs({value: 1});
31
var mapping_2 = dataTable.mapAs({value: 2});
32
33
// create a stock chart
34
chart = anychart.stock();
35
36
// create a plot on the chart
37
plot = chart.plot(0);
38
39
// create two line series
40
var series_1 = plot.line(mapping_1).name("Series 1");
41
var series_2 = plot.line(mapping_2).name("Series 2");
42
43
// add event markers
44
plot.eventMarkers({"groups": [
45
{
46
"data": [
47
{
48
"date": "2015-12-24",
49
"description": "Event 1"
50
},
51
{
52
"date": "2016-01-03",
53
"description": "Event 2"
54
},
55
{
56
"date": "2016-01-07",
57
"description": "Event 3"
58
},
59
]
60
}
61
]});
62
63
// bind event markers to the first series
64
plot.eventMarkers().position("series");
65
plot.eventMarkers().seriesId(0);
66
67
// set the chart title
68
chart.listen("chartDraw", function () {
69
chart.title("Event Markers: Position\n(series index = " +
70
plot.eventMarkers().seriesId() + ", position = " +
71
plot.eventMarkers().position() + ")");
72
});
73
74
// set the container id
75
chart.container("container");
76
77
// initiate drawing the chart
78
chart.draw();
79
});
80
81
// set the position of event markers
82
function setPosition() {
83
var seriesSelect = document.getElementById("seriesSelect");
84
var positionSelect = document.getElementById("positionSelect");
85
plot.eventMarkers().seriesId(seriesSelect.value);
86
plot.eventMarkers().position(positionSelect.value);
87
}