Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to position RangeSelector / zoom buttons at custom co-ordinates in Highstock

I am using highstock charts and wish to move the zoom buttons (1m,2m,etc) to a different position.

I checked their API and there doesn't seem to be an option to do that currently. Also the source code suggests that this location is hardcoded and hence i don't think I can easily inject the position using some undocumented property

Highstock Source

Highcharts.RangeSelector.prototype.render = function (min, max) {
...
rangeSelector.zoomText = renderer.text(lang.rangeSelectorZoom, plotLeft, chart.plotTop - 10)
                .css(options.labelStyle)
                .add();

// button starting position
buttonLeft = plotLeft + rangeSelector.zoomText.getBBox().width + 5;
...
}
like image 702
Jugal Thakkar Avatar asked Mar 14 '13 12:03

Jugal Thakkar


1 Answers

This can be done by overriding the current render method and then moving the boxes after calling the actual render method to a position desired

var orgHighchartsRangeSelectorPrototypeRender = Highcharts.RangeSelector.prototype.render;
Highcharts.RangeSelector.prototype.render = function (min, max) {
    orgHighchartsRangeSelectorPrototypeRender.apply(this, [min, max]);
    var leftPosition = this.chart.plotLeft,
        topPosition = this.chart.plotTop+5,
        space = 2;
    this.zoomText.attr({
        x: leftPosition,
        y: topPosition + 15
    });
    leftPosition += this.zoomText.getBBox().width;
    for (var i = 0; i < this.buttons.length; i++) {
        this.buttons[i].attr({
            x: leftPosition,
            y: topPosition 
        });
        leftPosition += this.buttons[i].width + space;
    }
};

This code needs to be run before creating any chart

Positioning Zoom buttons | Highchart & Highstock @ jsFiddle

like image 145
Jugal Thakkar Avatar answered Oct 24 '22 11:10

Jugal Thakkar