bahar_Agi
bahar_Agi

Reputation: 644

how to set a rangeSelector for highstock

I'm using highstock. How can I set the rangeSelector for the chart? I've used:

chart.rangeSelector({ selected: 5 });   *

but it didn't work.

I know to set it like this example: http://jsfiddle.net/Pffxt/2/ but I create the chart once and then add series. When I create the chart(like the example) and add series the rangeSelector doesn't work. I think I have to use like ***

Please help me! Thank you

Upvotes: 5

Views: 9725

Answers (4)

MilConDoin
MilConDoin

Reputation: 745

You don't have to give the rangeSelector the options to use. You can simply call:

chart.rangeSelector.clickButton(0, true);

Thus the first button will be clicked while using its current options.

Upvotes: 2

MCrossley
MCrossley

Reputation: 133

To use the clickButton() you need to call it like this...

chart.rangeSelector.clickButton(0, chart.rangeSelector.buttonOptions[0], true);

Where the buttonOptions[] item matches the first parameter.

Upvotes: 0

Sebastian Bochan
Sebastian Bochan

Reputation: 37578

In case when you destroy rangeseletor object, it is not possible to display object which doens't exist. So if you woudl like to display rangeselector only what you need is enable it by http://api.highcharts.com/highstock#rangeSelector.enabled.

Upvotes: 0

MatthewKremer
MatthewKremer

Reputation: 1569

Instead of using .rangeSelector({settings}), use the .clickButton function:

chart.rangeSelector.clickButton(0,{type: 'month', count: 1},true);

However, this function seems to be somewhat strange and undocumented from what I can tell.

It accepts the following arguments:

* @param {Number} i The index of the button
* @param {Object} rangeOptions
* @param {Boolean} redraw

redraw defaults to true, and i will just visually select one of the buttons (other than that, it seems to do nothing). The bread and butter seems to be in the rangeOptions, which is an object with a type and count. For instance, in the example above, it selects the most recent 1 month. Other available options are:

* millisecond
* second
* minute
* hour
* day
* week
* month
* ytd
* year
* all

However, please note that you cannot .destroy(); the range selector and have this still work, you would possibly have to do a little bit of hacking to get that to work.

Here is a JSFiddle illustrating it: http://jsfiddle.net/HFPr2/

Upvotes: 7

Related Questions