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/css/7.14.3/anychart-ui.css
4
// Download it, alter, upload to your server and link from your pages to change the look.
5
6
var stage = anychart.graphics.create("container");
7
8
var lineChart = anychart.line([1, 2, 1.3, 2.9]);
9
lineChart.bounds(0, 50, "50%", "100%");
10
lineChart.contextMenu(false);
11
12
var lineCustomContextMenu = anychart.ui.contextMenu();
13
14
// Attach context menu to the chart.
15
lineCustomContextMenu.attach(lineChart);
16
17
lineCustomContextMenu.itemsProvider(function () {
18
return [
19
{
20
text: "Open AnyChart API",
21
href: "https://api.anychart.com"
22
}
23
];
24
});
25
lineChart.container(stage);
26
lineChart.draw();
27
28
var columnChart = anychart.column([1, 2, 1.3, 2.9]);
29
columnChart.bounds("50%", 50, "50%", "100%");
30
columnChart.contextMenu(false);
31
var columnCustomContextMenu = anychart.ui.contextMenu();
32
columnCustomContextMenu.itemsProvider(function () {
33
return [
34
{
35
text: "Open AnyChart API",
36
href: "https://api.anychart.com"
37
}
38
];
39
});
40
columnChart.container(stage);
41
columnChart.draw();
42
43
var attachDetachLabel = anychart.standalones.label();
44
attachDetachLabel.background({fill: "#9E9E9E"});
45
attachDetachLabel.text("Detach/Attach.");
46
attachDetachLabel.fontColor("#fff");
47
attachDetachLabel.parentBounds(0, 0, 100, 100);
48
attachDetachLabel.padding(5);
49
attachDetachLabel.zIndex(1000);
50
attachDetachLabel.listen("click", function () {
51
52
// Detach the custom context menu from the line chart.
53
lineCustomContextMenu.detach(lineChart);
54
55
// Attach context menu to the column chart.
56
columnCustomContextMenu.attach(columnChart);
57
58
});
59
attachDetachLabel.container(stage);
60
attachDetachLabel.draw();
61
62
var customTitle = anychart.standalones.title();
63
customTitle.parentBounds("50%", 0, 100, 100);
64
customTitle.text("Detach/Attach a custom context menu to the chart. Click on labels and right-click on the chart.")
65
customTitle.container(stage);
66
customTitle.draw();
67
});