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

穿精又带淫゛_ 提交于 2019-12-18 06:39:04

问题


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;
...
}

回答1:


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




回答2:


At this moment it is not possible, but you can voice for it here http://highcharts.uservoice.com/forums/55896-general/suggestions/2436599-add-ability-to-change-rangeselector-position



来源:https://stackoverflow.com/questions/15409914/how-to-position-rangeselector-zoom-buttons-at-custom-co-ordinates-in-highstock

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