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.heatMap(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
{x: 'California', y: '2004', heat: 1704211},
36
{x: 'California', y: '2005', heat: 2782680},
37
{x: 'California', y: '2006', heat: 2992679},
38
{x: 'Illinois', y: '2004', heat: 727914},
39
{x: 'Illinois', y: '2005', heat: 1150659},
40
{x: 'Illinois', y: '2006', heat: 1134085},
41
{x: 'Massachusetts', y: '2004', heat: 238819},
42
{x: 'Massachusetts', y: '2005', heat: 157719},
43
{x: 'Massachusetts', y: '2006', heat: 887169},
44
{x: 'New York', y: '2004', heat: 1667969},
45
{x: 'New York', y: '2005', heat: 2763503},
46
{x: 'New York', y: '2006', heat: 3151022},
47
{x: 'Texas', y: '2004', heat: 219967},
48
{x: 'Texas', y: '2005', heat: 3732889},
49
{x: 'Texas', y: '2006', heat: 4185098}
50
]
51
}