HTMLcopy
1
<span id="info"></span>
2
<div id="container"></div>
CSScopy
12
1
html, body {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
7
#container {
8
position: absolute;
9
width: 100%;
10
top: 20px;
11
bottom: 0;
12
}
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
var chart = anychart.stock();
14
15
// create a plot on the chart
16
var plot = chart.plot(0);
17
18
// create a line series
19
plot.line(mapping).name("CSCO");
20
21
// add event markers
22
plot.eventMarkers({"groups": [
23
{
24
"data": [
25
{
26
"date": "2006-06-02",
27
"description": "Cisco announced the acquisition of Audium Corporation."
28
},
29
{
30
"date": "2008-04-27",
31
"description": "Cisco announced its intent to acquire PostPath, Inc."
32
}
33
]
34
}
35
]});
36
37
// show information when mouse is over a marker
38
chart.listen("eventMarkerMouseOver", function (e) {
39
var symbol = e.eventMarker.symbol;
40
var description = e.eventMarker.description;
41
var date = e.eventMarker.date;
42
document.getElementById("info").innerHTML =
43
symbol + "@" + anychart.format.date(date)
44
+ ": " + description;
45
});
46
47
// hide information when mouse leaves a marker
48
chart.listen("eventMarkerMouseOut", function () {
49
document.getElementById("info").innerHTML = "";
50
});
51
52
// open a url when a marker is clicked on
53
chart.listen("eventMarkerClick", function (e) {
54
var url = "https://www.google.ru/search?q=" +
55
e.eventMarker.description;
56
window.open(url, "_blank");
57
});
58
59
// set the chart title
60
chart.title("Event Markers: Events");
61
62
// set the container id
63
chart.container("container");
64
65
// initiate drawing the chart
66
chart.draw();
67
});