HTMLcopy
1
<div id="container"></div>
CSScopy
8
1
html,
2
body,
3
#container {
4
width: 100%;
5
height: 100%;
6
margin: 0;
7
padding: 0;
8
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
// To work with the data adapter you need to reference the data adapter script file from AnyChart CDN
3
// https://cdn.anychart.com/releases/v8/js/anychart-data-adapter.min.js
4
5
// Load JSON data and create a chart by JSON data
6
// The data used in this sample can be obtained from the CDN
7
// https://cdn.anychart.com/samples-data/general-features/html-tooltip/data.json
8
anychart.data.loadJsonFile(
9
'https://cdn.anychart.com/samples-data/general-features/html-tooltip/data.json',
10
function (data) {
11
// create and setup column chart
12
var chart = anychart.column().title('Smartphone sales by Month');
13
14
// set X axis labels font size
15
var labels = chart.xAxis().labels();
16
labels.fontSize(11);
17
18
// create dataset and map it for column chart
19
var dataSet = anychart.data.set(data);
20
var columnData = dataSet.mapAs({
21
x: 'month',
22
value: 'total'
23
});
24
25
// create column series
26
var series = chart.column(columnData);
27
28
// get tooltip
29
var tooltip = series.tooltip();
30
31
// enable html mode and format title and content of tooltip
32
tooltip
33
.useHtml(true)
34
.titleFormat('<h3>{%X}</h3>')
35
.format(
36
'<div>Total: {%Value}</div><div id="tooltip-container"></div>'
37
);
38
39
// create 3D pie chart with transparent background for tooltip
40
var tooltipChart = anychart.pie3d();
41
tooltipChart.height(150);
42
tooltipChart.background('transparent');
43
tooltipChart.legend().fontColor('#333');
44
45
// listen MouseOver event on column series
46
series.listen('pointMouseOver', function (e) {
47
// get data for tooltip chart
48
tooltipChart.data(e.iterator.get('data'));
49
});
50
51
// draw tooltip chart in it's content element if tooltip DOM is rendered
52
tooltip.onDomReady(function () {
53
tooltipChart.container(this.contentElement);
54
tooltipChart.draw();
55
});
56
57
// Prevent overriding tooltip content
58
tooltip.onBeforeContentChange(function () {
59
return false;
60
});
61
62
// set container id for the chart
63
chart.container('container');
64
65
// initiate chart drawing
66
chart.draw();
67
}
68
);
69
});