HTMLcopy
1
<div id="container"></div>
CSScopy
6
1
html, body, #container {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
3
tooltip = $("<div class='custom-tooltip'></div>").css({
4
"position": "absolute",
5
"pointerEvents": "none",
6
"width": "100px",
7
"background": "#fff",
8
"padding": "4px",
9
"border": "solid black 2px",
10
"display": "none"
11
});
12
13
// data
14
var data = anychart.data.set([
15
["Velma", 10],
16
["Fred", 12],
17
["Daphne", 18],
18
["Shaggy", 6],
19
["Scooby", 46]
20
]);
21
22
23
// map data for the each series
24
var dataMapping = data.mapAs({x: [0], value: [1]});
25
26
// chart type
27
var chart = anychart.column(dataMapping);
28
29
// set data
30
var series = chart.getSeries(0);
31
series.tooltip(false);
32
33
// chart title
34
chart.title().useHtml(true);
35
chart.title('<span style="color:#545f69; font-size: 18px;">How many pieces of pizza have they eaten?</span>');
36
37
// switching the selection mode to single
38
chart.interactivity().selectionMode("singleSelect");
39
40
series.stroke(null);
41
42
// enable legend
43
chart.legend().enabled(false);
44
45
chart.listen("mouseMove", function (e) {
46
var clientX = e['offsetX'];
47
var clientY = e['offsetY'];
48
var $container = $(this.container().getStage().container());
49
50
if (!$container.find('.custom-tooltip').length) {
51
$container.append(tooltip);
52
}
53
54
tooltip.css({"left": clientX + 20, "top": clientY + 10, "z-index": 10000});
55
});
56
57
chart.listen("pointMouseOver", function (e) {
58
tooltip.css({"display": "block"});
59
60
var ind = e.pointIndex;
61
tooltip.html(data.row(ind)[0] + " has eaten " + data.row(ind)[1] + " pieces of pizza in total");
62
});
63
64
chart.listen("pointMouseOut", function () {
65
tooltip.css("display", "none");
66
});
67
68
// draw
69
chart.container("container");
70
chart.draw();
71
});