bil*_*rky 0 javascript highcharts highstock
有谁知道如何在highcharts中动态添加或删除"导出"按钮?
我已经能够使用类似于此的代码成功添加按钮:
exporting: {
buttons: {
customButton: {
text: 'Custom Button',
onclick: function () {
alert('You pressed the button!');
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我希望以后能够通过javascript事件将该按钮添加到图表中(然后很快将其删除).
使用塞巴斯蒂安提供的方向,我能够完全解决这个问题.
这里可以找到通过渲染器添加按钮的文档(遗憾的是,没有信息在highcharts官方api中):http://forum.highcharts.com/viewtopic.php? f = 9&t = 15416
这是重要的部分:
/**
* 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) {}
Run Code Online (Sandbox Code Playgroud)
这是我使用的代码:
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();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3502 次 |
| 最近记录: |