HTMLcopy
1
<div id="tooltip" class="custom-tooltip"></div>
2
<div id="container"></div>
CSScopy
15
1
html, body, #container {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
7
.custom-tooltip {
8
visibility: hidden;
9
pointer-events: none;
10
position: absolute;
11
width: 100px;
12
padding: 4px;
13
border: solid black 2px;
14
background: #fff;
15
}
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-08",
27
"description": "Audium Corporation Acquisition"
28
},
29
{
30
"date": "2008-04-27",
31
"description": "PostPath Acquisition"
32
}
33
]
34
}
35
]});
36
37
// disable the built-in tooltips of event markers
38
var eventMarker = plot.eventMarkers();
39
eventMarker.tooltip(false);
40
41
var tooltip = document.getElementById("tooltip");
42
43
/* show a custom tooltip
44
when the mouse is over a marker */
45
eventMarker.listen("eventMarkerMouseOver", function(e) {
46
47
// show the tooltip
48
tooltip.style.visibility = "visible";
49
50
// set the text of the tooltip
51
tooltip.innerHTML = e.eventMarker.description;
52
});
53
54
/* hide the custom tooltip
55
when the mouse is out of a marker */
56
eventMarker.listen("eventMarkerMouseOut", function() {
57
tooltip.style.visibility = "hidden";
58
});
59
60
// set the position of custom tooltips
61
chart.listen("mouseMove", function(e) {
62
var clientX = e["offsetX"];
63
var clientY = e["offsetY"];
64
tooltip.style.left = clientX + 20 + "px";
65
tooltip.style.top = clientY + 10 + "px";
66
tooltip.style.zIndex = 10000;
67
tooltip.style.border = "solid black 2px";
68
});
69
70
// set the chart title
71
chart.title("Event Markers: Custom HTML Tooltips");
72
73
// set the container id
74
chart.container("container");
75
76
// initiate drawing the chart
77
chart.draw();
78
});