简体   繁体   English

如何限制 highstock.js 中导航器的大小?

[英]How can I limit the size of the navigator in highstock.js?

I have an application with long time series and I want to limit the maximum size of the navigator.我有一个时间序列很长的应用程序,我想限制导航器的最大大小。 I found the afterSetExtremes event in the documentation, which I thought I could capture and then limit the size of the navigator from there.我在文档中找到了afterSetExtremes事件,我认为我可以捕获它,然后从那里限制导航器的大小。 But it doesn't really work as expected.但它并没有真正按预期工作。 I seem to be able to limit the x size of the plotted data.我似乎能够限制绘制数据的 x 大小。 But the navigator doesn't follow the size of the plotted data at all.但是导航器根本不遵循绘制数据的大小。 Am i missing something here?我在这里错过了什么吗? How can I get it to work properly?我怎样才能让它正常工作? Ideally the navigator would just remain fixed in size over a specific size.理想情况下,导航器将在特定大小上保持固定大小。 Is that possible to achieve?这有可能实现吗?

Here the jsfiddle:这里是jsfiddle:

http://jsfiddle.net/jn3cww8n/2/ http://jsfiddle.net/jn3cww8n/2/

$(function () {
$('#container').highcharts('StockChart', {
    xAxis: {
        events: {
            afterSetExtremes: function(e) {

                var dmin = Math.abs(e.min - this.oldMin),
                    dmax = Math.abs(e.max - this.oldMax),
                    range = e.max - e.min,
                    new_min = e.min,
                    new_max = e.max,
                    yr_range = range / 1000 / 60 / 60 / 24;
                if (0.0 === dmin && 0.0 < dmax) {
                    $('#report').html('Max changed ' + yr_range);

                    if (31536000000.0 < range) {
                        $('#report').html('setting new max');
                        new_max = new_min + 31536000000.0;
                    }

                } else if (0.0 < dmin && 0.0 === dmax) {
                    $('#report').html('Min changed ' + yr_range);

                    if (31536000000.0 < range) {
                        $('#report').html('setting new min');
                        new_min = new_max - 31536000000.0;
                    }

                } else {
                    $('#report').html('Nothing changed');
                }

                this.setExtremes(new_min, new_max);

            }
        }
    },
    rangeSelector: {
        selected: 1
    },
    series: [{
        name: 'USD to EUR',
        data: usdeur
    }]
});
});

I changed tack on this one.我改变了这一点。 Instead of having a max size of the navigator, I restricted users from changing its size altogether.我没有设置导航器的最大尺寸,而是限制用户完全更改其尺寸。

I got the idea from this post.我从这篇文章中得到了这个想法。

Just two changes required:只需要两个改变:

  1. Blank the drawHandle function Highcharts.Scroller.prototype.drawHandle = function () {};清空drawHandle函数Highcharts.Scroller.prototype.drawHandle = function () {};
  2. Commment out a few lines:注释掉几行:

     22472,22476c22472,22476 < //if (isOnNavigator && math.abs(chartX - zoomedMin - navigatorLeft) < handleSensitivity) { < //scroller.grabbedLeft = true; < //scroller.otherHandlePos = zoomedMax; < //scroller.fixedExtreme = baseXAxis.max; < //chart.fixedRange = null; --- > if (isOnNavigator && math.abs(chartX - zoomedMin - navigatorLeft) < handleSensitivity) { > scroller.grabbedLeft = true; > scroller.otherHandlePos = zoomedMax; > scroller.fixedExtreme = baseXAxis.max; > chart.fixedRange = null; 22479,22483c22479,22483 < //} else if (isOnNavigator && math.abs(chartX - zoomedMax - navigatorLeft) < handleSensitivity) { < //scroller.grabbedRight = true; < //scroller.otherHandlePos = zoomedMin; < //scroller.fixedExtreme = baseXAxis.min; < //chart.fixedRange = null; --- > } else if (isOnNavigator && math.abs(chartX - zoomedMax - navigatorLeft) < handleSensitivity) { > scroller.grabbedRight = true; > scroller.otherHandlePos = zoomedMin; > scroller.fixedExtreme = baseXAxis.min; > chart.fixedRange = null; 22486,22487c22486 < //} else if (chartX > navigatorLeft + zoomedMin - scrollbarPad && chartX < navigatorLeft + zoomedMax + scrollbarPad) { < if (chartX > navigatorLeft + zoomedMin - scrollbarPad && chartX < navigatorLeft + zoomedMax + scrollbarPad) { --- > } else if (chartX > navigatorLeft + zoomedMin - scrollbarPad && chartX < navigatorLeft + zoomedMax + scrollbarPad) {

Pretty clean all in all.总之很干净。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 highstock.js图表​​绘制有点偏离 - highstock.js chart plotting is a bit off HighStock.js标志工具提示框格式 - HighStock.js flags tooltip box formatting Highstock.js问题:如何只为当日数据绘制VWAP指标? - Highstock.js question: how to draw VWAP indicator only for current day data? 如何从 Highstock 图表中获取导航器选择? - How can I get the navigator selection from a Highstock chart? 在Highstock.js中显示Highstock.js中每个系列的标签 - Show labels per serie in Highstock.js as in Highcharts.js highstock.js日期范围少于一个小时不起作用 - highstock.js date ranges less then a hour don't work 如果超过2000点,Highstock.js将显示错误的值 - Highstock.js display incorrect value if more than 2000 points 当我在不同的时间间隔中有多个序列时,该如何解决highstock中的导航器问题? - How can I fix the navigator issue in highstock when I have more than 1 series in different time intervals? Highstock.js:无法使用两个堆叠的柱形图(一个为“正常”而另一个为“百分比”)创建多窗格图 - Highstock.js: Not able to create multi pane chart with two stacked column charts, one “normal” and the other “percent” 当存在xAxis配置字段时,Highstock.js / Angular.js中的范围选择器不会更新图表 - Range selector in Highstock.js / Angular.js doesn't update chart when xAxis configuration field is present
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM