Highstock - 最小缩放 [英] Highstock - Minimal Zoom

查看:152
本文介绍了Highstock - 最小缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Highstock中为导航器设置最小缩放(36个月)?
i已经尝试过,但它不起作用,你有想法吗?

How can you set in Highstock a minimal zoom (36 Months) for Navigator? i have tried this but it doesnt work do you have a idea?

http://jsfiddle.net/B7vCR/6/

http://jsfiddle.net/B7vCR/6/

$(function() {

    var chart;
    $.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback=?', function(data) {
        // Create the chart
        chart = new Highcharts.StockChart({
            chart: {
                renderTo: 'container'
            },

            rangeSelector: {
                selected: 1
            },

            title: {
                text: 'AAPL Stock Price'
            },
            xAxis: {
                minRange:6 * 30 * 24 * 3600 * 1000,
                events: {
                    afterSetExtremes: function(e) {
                        var maxDistance = 10 * 30 * 24 * 3600 * 1000; //8 months time
                        var xaxis = this;
                        if ((e.max - e.min) < maxDistance) {
                            var min = e.max - maxDistance;
                            var max = e.max;
                            window.setTimeout(function() {
                                xaxis.setExtremes(min, max);
                            }, 1);
                        }
                    }
                }
            },
            series: [{
                name: 'AAPL',
                data: data,
                tooltip: {
                    valueDecimals: 2
                }}]
        });
    });

});


推荐答案

您需要配置按钮如果您想要范围选择器

You need to configure buttons if you want the range selector

xAxis: {
    events: {
        afterSetExtremes: function(e) {
            var minDistance = 36 * 30 * 24 * 3600 * 1000; //36 months time
            var xaxis = this;
            if ((e.max - e.min) < minDistance) {
                var min = e.max - minDistance;
                var max = e.max;
                window.setTimeout(function() {
                    xaxis.setExtremes(min, max);
                }, 1);
            }
        }
    }
}
rangeSelector: {
    selected : 1,
    buttons: [{
        type: 'month',
        count: 36,
        text: '36m'
    }, {
        type: 'month',
        count: 42,
        text: '42m'
    }, {
        type: 'month',
        count: 48,
        text: '48m'
    }, {
        type: 'month',
        count: 54,
        text: '54m'
    }, {
        type: 'all',
        text: 'All'
    }]
}

工作jsFiddle: http://jsfiddle.net/Zd5Cn/

working jsFiddle: http://jsfiddle.net/Zd5Cn/

这篇关于Highstock - 最小缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆