【问题标题】:ZoomRange Highstock works not correct?ZoomRange Highstock 工作不正确?
【发布时间】:2016-04-11 11:24:55
【问题描述】:

我制作了一个 Highstock 图表,但在缩放 yAxis 时遇到了问题。 我有一个 Button 和 2 个文本字段来获取轴的所需最小/最大值。使用 min:0, max: 100 效果很好。使用 min:0, max:80 则不会(图表中的最大值仍为 100)。 如果我使用鼠标进行缩放,它工作得很好(甚至最小:3.7 和最大 3.894 是可能的)。但是使用鼠标不是一个选项,因为在后面的 Diagramm 中会有 3 个 yAxes 单独缩放。

$(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

另一个问题:是否也可以为 yAxis 设置滚动条? 谢谢你的帮助,帕特里克

【问题讨论】:

    标签: max zooming highstock min axes


    【解决方案1】:

    这与tickInterval 不规则的事实有关,因此被四舍五入为值(如100)。解决方案是使用 tickPositioner,它根据您定义的极端值计算刻度。

    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/

    只有 xAxis 支持滚动条。

    【讨论】:

    • 非常感谢,这正是我要找的。​​span>
    猜你喜欢
    • 1970-01-01
    • 2017-06-10
    • 2014-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多