ZoomRange Highstock works not correct?

倖福魔咒の 提交于 2019-12-12 02:38:04

问题


I made a Highstock diagramm and got aproblem with zooming on the yAxis. I have a Button and 2 textfield to get the wanted min/max values for the axis. With min:0, max: 100 it works well. With min:0, max:80 it doesn't (max will still be 100 in the Diagramm). If I use the mouse for zooming it works well (even a min of: 3.7 and a max of 3.894 is possible). But using the mouse is not an Option, because in the later Diagramm there will be 3 yAxes with individual zoom.

$(function () {
var seriesOptions = [],
    seriesCounter = 0,
    names = ['MSFT', 'AAPL', 'GOOG'];

/**
 * Create the chart when all data is loaded
 * @returns {undefined}
 */
function createChart() {

    $('#container').highcharts('StockChart', {
        rangeSelector: {
            selected: 4
        },
        chart:{
            zoomType: 'xy'
        },
        yAxis: [
        {
            labels: {
               format: '{value}',
            },
            height: '100%',
            opposite: false,
            plotLines: [{
                value: 0,
                width: 2,
                color: 'silver'
            }]
        },
        ],

        plotOptions: {
            series: {
                compare: 'percent'
            }
        },

        tooltip: {
            pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>',
            valueDecimals: 2
        },

        series: seriesOptions
    },
    function(chart){

        $('#btn').click(function(){
            var min = temp_min.value,
                max = temp_max.value;
            chart.yAxis[0].setExtremes((min),(max)); 
        });

    });
}

$.each(names, function (i, name) {

    $.getJSON('https://www.highcharts.com/samples/data/jsonp.php?filename=' + name.toLowerCase() + '-c.json&callback=?',    function (data) {
                    if(seriesCounter==0){            
            seriesOptions[i] = {
            name: name,
            data: data,
            yAxis: 0
            };
        } else {
           seriesOptions[i] = {
            name: name,
            data: data,
            yAxis: 0
            };
        }



        // As we're loading the data asynchronously, we don't know what order it will arrive. So
        // we keep a counter and create the chart when all the data is loaded.
        seriesCounter += 1;

        if (seriesCounter === names.length) {
            createChart();
        }
    });
});

});

JSFiddle

Another Question: Is it possible to set up a scrollbar for the yAxis as well? Thanks for your help, Patrick


回答1:


This is related with fact that tickInterval is not regular, so is rounded to value (like 100). The solution is using tickPositioner which calculates ticks, based on extremes which you define.

tickPositioner: function (min,max) {
            var positions = [],
                tick = Math.floor(min),
                increment = Math.ceil((max - min) / 5);

            for (tick; tick - increment <= max; tick += increment) {
                positions.push(tick);
            }
            return positions;
        },

http://jsfiddle.net/6s11kcwd/

The scrollbar is supported only for xAxis.



来源:https://stackoverflow.com/questions/34648919/zoomrange-highstock-works-not-correct

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