2013-08-23 40 views
0

有誰知道如何動態添加或刪除高級圖表中的「導出」按鈕?動態添加和刪除高級圖表中的自定義導出按鈕

我已經能夠使用類似於此代碼成功添加一個按鈕:

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

但我希望能夠在以後通過JavaScript事件添加按鈕拖到圖(然後之後馬上將其刪除)。

+1

你可以通過渲染器添加按鈕和函數http://stackoverflow.com/questions/15472330/highcharts-replace-custom-button-image-on-hover –

回答

6

使用塞巴斯蒂安提供的方向,我能夠完全解決這個問題。

爲通過渲染器添加按鈕文檔可以在這裏找到(無信息是在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(); 
相關問題