如何从 Highcharts 移除按钮

我正在创建图表与高图库,我不知道如何删除右角的2个小按钮,你可以打印和下载图表,我想添加一个新的。

也许有人能帮我?

87473 次浏览

Try adding exporting: { enabled: false } to your chart generation.

Check this to create new button:

Example: http://jsfiddle.net/fXHB5/3496/

exporting: {
buttons: [
{
symbol: 'diamond',
x: -62,
symbolFill: '#B5C9DF',
hoverSymbolFill: '#779ABF',
_titleKey: 'printButtonTitle',
onclick: function() {
alert('click!')
}
}
]
}
exporting:false,

Add the above code to disable export option.

@dgw has the right idea to remove the export buttons, but I wasn't happy with the "and I'd like to add a new one" suggestions until I realized I should just make the buttons outside the graph. Unless your data is static, you don't really know if there's room to display your controls.

<div id="container" style="height: 400px; min-width: 600px"></div>
<button id="button" class="autocompare">new button</button>
exporting: {
buttons: {
contextButton: {
enabled: false
}
}
}

You have to disable only the contextButton.

The best way to replace the hamburger icon is to disable the navigation buttonOptions, then create your own menu and customize the context one by one as stated in the documentation. From here you can use any icon you want with your own dropdown menu.

This disables the hamburger icon.

navigation: {
buttonOptions: {
enabled: false
}
}

This is how you customize export options for your own list.

$('#print').click(function() {
chart.print();
});
$('#pdf').click(function() {
chart.exportChart({
type: 'application/pdf',
filename: 'my-pdf'
});
});
$('#png').click(function() {
chart.exportChart({
type: 'image/png',
filename: 'my-png'
});
});
$('#jpeg').click(function() {
chart.exportChart({
type: 'image/jpeg',
filename: 'my-jpeg'
});
});
$('#svg').click(function() {
chart.exportChart({
type: 'image/svg+xml',
filename: 'my-svg'
});
});

jsfiddle

Other option is: you can just remove import of "node_modules/highcharts/modules/exporting.js" from the whole project if you don't need it at all.

That was a solution for me!

The best way to do this is to update the exporting.buttons.contextButton.menuItems array to only include the menu items you want. Below is an example that excludes the "Print Chart" and "View Full Screen" options.

exporting: {
buttons: {
contextButton: {
menuItems: ["downloadPNG", "downloadJPEG", "downloadPDF", "downloadSVG"]
}
}
}

Highcharts Example