Javascript 动态添加和删除highcharts中的自定义导出按钮
有人知道如何在highcharts中动态添加或删除“导出”按钮吗 我已经能够使用类似以下代码成功添加按钮:Javascript 动态添加和删除highcharts中的自定义导出按钮,javascript,highcharts,highstock,Javascript,Highcharts,Highstock,有人知道如何在highcharts中动态添加或删除“导出”按钮吗 我已经能够使用类似以下代码成功添加按钮: exporting: { buttons: { customButton: { text: 'Custom Button', onclick: function () { alert('You pressed the button!');
exporting: {
buttons: {
customButton: {
text: 'Custom Button',
onclick: function () {
alert('You pressed the button!');
}
}
}
}
但是我希望稍后能够通过javascript事件将按钮添加到图形上(然后很快将其删除)。使用Sebastian提供的方向,我能够完全解决这个问题 可在此处找到通过渲染器添加按钮的文档(highcharts官方api中没有信息): 以下是重要部分:
/**
* Create a button with preset states
* @param {String} text
* @param {Number} x
* @param {Number} y
* @param {Function} callback
* @param {Object} normalState
* @param {Object} hoverState
* @param {Object} pressedState
*/
button: function (text, x, y, callback, normalState, hoverState, pressedState) {}
以下是我使用的代码:
hChart是highcharts主对象
hChart.drillupCustomButton = hChart.renderer.button(
'DRILL BACK UP',
100,
7,
function(){
//run whatever code you want here for when button is clicked
//This next line of code is how you remove the button (I chose to remove the button when the button is clicked)
$(hChart.drillupCustomButton.element).remove();
//You could also remove it via the id like this
$('#drillupCustomButtonID').remove();
},
null,
null,
null
)
.attr({
id: 'drillupCustomButtonID'
})
.add();
可以通过渲染器添加按钮和函数