HTMLcopy
1
<div id="container"></div>
CSScopy
13
1
html, body, #container {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
7
.anychart-tooltip {
8
background-color: white;
9
border-color: #455a64;
10
border-style: solid;
11
border-width: 3px;
12
color: #455a64;
13
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
3
// create data
4
data = anychart.data.set([
5
["2000", 10048, 2600, 3200, 2159, 2089],
6
["2001", 10938, 2367, 1989, 2383, 4199],
7
["2002", 9989, 2156, 2399, 2867, 2567],
8
["2003", 10226, 2398, 2225, 3010, 2593],
9
["2004", 11004, 2851, 3007, 2805, 2341],
10
["2005", 10934, 3400, 2105, 2563, 2866],
11
["2006", 11275, 2878, 2933, 3561, 1903],
12
["2007", 11945, 2959, 3855, 3109, 2022],
13
["2008", 12245, 4001, 2156, 3928, 2160],
14
["2009", 12056, 1995, 2057, 4902, 3102],
15
["2010", 11734, 2584, 3166, 3101, 2883],
16
["2011", 12337, 3106, 2845, 2933, 3453],
17
["2012", 12761, 3296, 2655, 3144, 3666],
18
["2013", 13390, 2611, 4194, 3206, 3379],
19
["2014", 13818, 3000, 2599, 4107, 4112],
20
["2015", 13188, 3199, 2564, 3118, 4307]
21
]);
22
23
// map the data
24
var dataMapping = data.mapAs({x: 0, value: 1});
25
26
// create a column chart
27
var chart = anychart.column();
28
29
// set the data
30
var column = chart.column(dataMapping);
31
32
// set the chart title
33
chart.title().useHtml(true);
34
chart.title("Tooltip: HTML (Chart as Tooltip)<br><br><span style='font-style:italic'>Sales Volume</span>");
35
36
// configure tooltips
37
chart.tooltip().useHtml(true);
38
chart.tooltip().separator(false);
39
chart.tooltip().title(false);
40
41
var tooltipChart = null;
42
43
/* listen to the pointMouseOver event
44
and update the tooltip chart or create one */
45
chart.listen("pointMouseOver", function(e) {
46
// get the data for the current point
47
var index = e.pointIndex;
48
var dataRow = data.row(index);
49
50
/* create a tooltip chart
51
or update the chart created before */
52
if (tooltipChart == null) tooltipChart = createChart();
53
tooltipChart.data([
54
{x: "John", value: dataRow[2]},
55
{x: "James", value: dataRow[3]},
56
{x: "Peter", value: dataRow[4]},
57
{x: "Mathew", value: dataRow[5]}
58
]);
59
tooltipChart.title(dataRow[0] + ": Sales per Employee");
60
});
61
62
/* listen to the onDomReady event
63
and draw a tooltip chart */
64
chart.tooltip().onDomReady(function() {
65
66
// configure the contentElement div of the tooltip
67
this.contentElement.style.width = "200px";
68
this.contentElement.style.height = "140px";
69
70
/* assign the contentElement div
71
as a container for the tooltip chart */
72
tooltipChart.container(this.contentElement);
73
console.log(this);
74
75
// initiate drawing the chart
76
tooltipChart.draw();
77
});
78
79
/* prevent the content of the contentElement div
80
from being overridden by the default formatter */
81
chart.tooltip().onBeforeContentChange(function() {
82
return false;
83
});
84
85
// set the container id
86
chart.container("container");
87
88
// initiate drawing the chart
89
chart.draw();
90
});
91
92
// create a tooltip chart
93
function createChart() {
94
95
// create a bar chart
96
var chart = anychart.bar();
97
98
// configure axes and labels
99
chart.xAxis().stroke(null).ticks(false);
100
chart.xAxis().labels().fontSize(10);
101
chart.yAxis().labels().fontSize(10);
102
103
// set padding
104
chart.padding([0, 12, 0, 0]);
105
106
// configure the chart title
107
chart.title().fontSize(12);
108
109
return chart;
110
}