最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Dynamically add and remove custom export button in highcharts - Stack Overflow

programmeradmin2浏览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).

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).

Share Improve this question asked Aug 23, 2013 at 0:39 billmalarkybillmalarky 9602 gold badges12 silver badges35 bronze badges 1
  • 1 You can add button and function by renderer stackoverflow./questions/15472330/… – Sebastian Bochan Commented Aug 23, 2013 at 9:39
Add a ment  | 

1 Answer 1

Reset to default 8

Using the direction Sebastian provided, I was able to fully solve this.

Documentation for adding buttons via renderer is found here (no info is in the highcharts official api unfortunately): http://forum.highcharts./viewtopic.php?f=9&t=15416

Here is the important part:

/**
* 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) {}

Here is the code I used:

hChart is the highcharts master object.

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();
发布评论

评论列表(0)

  1. 暂无评论