0

Does anyone know how to dynamically add or remove an "exporting" button in highcharts?

I've been able to successfully add a button using code similar to this:

exporting: {
        buttons: {
            customButton: {
                text: 'Custom Button',
                onclick: function () {
                    alert('You pressed the button!');
                }
            }
        }
    }

But I'd like to be able to add the button onto the graph later through a javascript event (and then remove it soon after).

4

1 回答 1

8

使用塞巴斯蒂安提供的方向,我能够完全解决这个问题。

在这里可以找到通过渲染器添加按钮的文档(不幸的是,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) {}

这是我使用的代码:

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();
于 2013-08-23T18:42:30.260 回答