HTMLcopy
1
<label for="positionSelect">Position: </label>
2
<select id="positionSelect" onchange="setPosition()">
3
<option value="axis">axis</option>
4
<option value="series">series</option>
5
</select>
6
<label id="fieldSelectId" for="fieldSelect">Field: </label>
7
<select id="fieldSelect" onchange="setPosition()">
8
<option value="open" selected>open</option>
9
<option value="high">high</option>
10
<option value="low">low</option>
11
<option value="close">close</option>
12
</select>
13
<div id="container"></div>
CSScopy
19
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
}
17
#fieldSelect, #fieldSelectId {
18
visibility: hidden;
19
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
3
// create data
4
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, 505.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
var mapping = dataTable.mapAs({open: 1, high: 2, low: 3, close: 4});
29
30
// create a stock chart
31
chart = anychart.stock();
32
33
// create a plot on the chart
34
plot = chart.plot(0);
35
36
// create an ohlc series
37
plot.ohlc(mapping);
38
39
// add event markers
40
plot.eventMarkers({"groups": [
41
{
42
"data": [
43
{
44
"date": "2015-12-24",
45
"description": "Event 1"
46
},
47
{
48
"date": "2015-12-27",
49
"description": "Event 2"
50
},
51
]
52
}
53
]});
54
55
// set the chart title
56
chart.title("Event Markers: Position");
57
58
// set the container id
59
chart.container("container");
60
61
// initiate drawing the chart
62
chart.draw();
63
});
64
65
// set the position of event markers
66
function setPosition() {
67
var positionSelect = document.getElementById("positionSelect");
68
var fieldSelect = document.getElementById("fieldSelect");
69
var fieldSelectId = document.getElementById("fieldSelectId");
70
plot.eventMarkers().position(positionSelect.value);
71
if (positionSelect.value == "axis") {
72
fieldSelect.style.visibility = "hidden";
73
fieldSelectId.style.visibility = "hidden";
74
// update the chart title
75
chart.title("Event Markers: Position\n(position = " +
76
plot.eventMarkers().position() + ")");
77
} else {
78
fieldSelect.style.visibility = "visible";
79
fieldSelectId.style.visibility = "visible";
80
plot.eventMarkers().fieldName(fieldSelect.value);
81
// update the chart title
82
chart.title("Event Markers: Position\n(position = " +
83
plot.eventMarkers().position() + ", field = " +
84
plot.eventMarkers().fieldName() + ")");
85
}
86
}