[英]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:只需要两个改变:
Highcharts.Scroller.prototype.drawHandle = function () {};
Highcharts.Scroller.prototype.drawHandle = function () {};
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.