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
var tooltipChart = null;
2
var title = null;
3
anychart.onDocumentReady(function () {
4
var 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
var dataMapping = data.mapAs({x: 0, value: 1});
24
25
chart = anychart.column(dataMapping);
26
27
var tooltip = chart.tooltip();
28
tooltip.useHtml(true);
29
tooltip.separator(false);
30
31
// Create a tooltip chart and title.
32
tooltip.onDomReady(function() {
33
this.contentElement.style.width = '200px';
34
this.contentElement.style.height = '150px';
35
tooltipChart.container(this.contentElement);
36
tooltipChart.draw();
37
38
this.titleElement.style.width = '200px';
39
this.titleElement.style.height = '60px';
40
title.container(this.titleElement);
41
title.draw();
42
43
});
44
45
tooltip.onBeforeTitleChange(function() {
46
// Prevent overriding content of this.titleElement
47
return false;
48
});
49
50
tooltip.onBeforeContentChange(function() {
51
// Prevent overriding content of this.contentElement
52
return false;
53
});
54
55
chart.listen('pointMouseOver', function(e) {
56
var index = e.pointIndex;
57
var dataRow = data.row(index);
58
tooltipChart = tooltipChart || createChart();
59
tooltipChart.data([
60
{x: 'John', value: dataRow[2]},
61
{x: 'James', value: dataRow[3]},
62
{x: 'Peter', value: dataRow[4]},
63
{x: 'Mary', value: dataRow[5]}
64
]);
65
title = title || anychart.standalones.title();
66
title.text("Sales Persons Share: " + dataRow[0]);
67
title.fontColor('#ffffff');
68
});
69
70
chart.title('Set onDomReady and onBeforeTitleChange, onBeforeContentChange handlers');
71
chart.container('container');
72
chart.draw();
73
});
74
75
function createChart() {
76
var chart = anychart.bar();
77
chart.title().fontSize(12);
78
chart.xAxis().stroke(null).ticks(false);
79
chart.xAxis().labels().fontSize(10);
80
chart.yAxis().labels().fontSize(10);
81
chart.padding([0, 12, 0, 0]);
82
return chart;
83
};