which rangeSelector button is selected in highcharts

六眼飞鱼酱① 提交于 2019-11-27 07:18:43

问题


I want to know how to determine which rangeSelector button is selected in highstock.

my rangeSelector buttons:

   buttons: [{
            type: 'month',
            count: 1,
            text: '1 MONTH',
        }, {
            type: 'month',
            count: 3,
            text: '3 MONTH'
        }, {
            type: 'month',
            count: 6,
            text: '6 MONTH'
        }, {
            type: 'ytd',
            text: 'YTD'
        }, {
            type: 'year',
            count: 1,
            text: '1 YEAR'
        }, {
            type: 'all',
            text: 'ALL'
        }],

for example I click on my first rangeSelector that is 1 MONTH. I want to know if this button is selected or not.

Is there any event?

Thanks


回答1:


You can catch setExtremes() (http://api.highcharts.com/highstock#xAxis.events.setExtremes), and then in event obejct you have access to event.rangeSelectorButton object with count, text and type property.

 xAxis: {
        events: {
            setExtremes: function(e) {
                console.log(this);
                if(typeof(e.rangeSelectorButton)!== 'undefined')
                {
                  alert('count: '+e.rangeSelectorButton.count + 'text: ' +e.rangeSelectorButton.text + ' type:' + e.rangeSelectorButton.type);
                }
            }
        }
    },

http://jsfiddle.net/E6GHC/1/




回答2:


You can get the a lot of information about the selected button directly from the rangeSelector.

For example:

var chart = $('#container').highcharts();

var selected = chart.rangeSelector.selected; // Index of selected button
var text = chart.rangeSelector.buttonOptions[selected].text; // Text of selected button
var type = chart.rangeSelector.buttonOptions[selected].type; // Type of selected button

And some other random information in buttonOptions and buttons under rangeSelector, using the selected index.

See this JSFiddle demonstration to see it in action.



来源:https://stackoverflow.com/questions/15846859/which-rangeselector-button-is-selected-in-highcharts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!