bahar_Agi
bahar_Agi

Reputation: 644

which rangeSelector button is selected in highcharts

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

Upvotes: 2

Views: 7013

Answers (2)

Halvor Holsten Strand
Halvor Holsten Strand

Reputation: 20536

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.

Upvotes: -1

Sebastian Bochan
Sebastian Bochan

Reputation: 37588

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/

Upvotes: 6

Related Questions