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
// To change the way how context menu looks you need to change CSS.
3
// By default CSS from AnyChart CDN is used: https://cdn.anychart.com/releases/8.13.0/css/anychart-ui.min.css
4
// Download it, alter, upload to your server and link from your pages to change the look.
5
6
var data = getData();
7
8
var chart = anychart.treeMap(data);
9
10
// Get context menu.
11
var contextMenu = chart.contextMenu();
12
13
contextMenu.itemsFormatter(function (items) {
14
15
items['custom-item'] = {
16
index: 1000,
17
text: 'Custom Context Menu Item',
18
action: actionHandler
19
};
20
21
return items;
22
});
23
24
function actionHandler() {
25
alert('Custom Item Clicked');
26
}
27
28
chart.title('Get and modify context menu. Right-click on the chart');
29
chart.container('container');
30
chart.draw();
31
});
32
33
function getData() {
34
return [
35
{
36
name: 'Eurasia',
37
children: [
38
{
39
name: 'Asia', children: [
40
{
41
name: 'Eastern Asia', children: [
42
{name: 'Mongolia', value: 1564116, capital: 'Ulan-Bator'},
43
{name: 'China', value: 1564116, capital: 'Beijing'},
44
{name: 'Southern Korea', value: 1564116, capital: 'Seoul'},
45
{name: 'Northern Korea', value: 120540, capital: 'Pyongyang'},
46
{name: 'Japan', value: 1564116, capital: 'Tokio'}
47
]
48
}
49
]
50
},
51
{
52
name: 'Europe', children: [
53
{
54
name: 'Northern Europe', children: [
55
{name: 'Finland', value: 338424, capital: 'Helsinki'},
56
{name: 'Great Britain', value: 209331, capital: 'London'},
57
{name: 'Ireland', value: 84421, capital: 'Dublin'},
58
{name: 'Scandinavia', value: 928057}
59
]
60
}
61
]
62
}
63
]
64
}
65
];
66
}