如何限制 highstock.js 中导航器的大小?
How can I limit the size of the navigator in highstock.js?
我有一个时间序列很长的应用程序,我想限制导航器的最大尺寸。我在文档中找到了 afterSetExtremes 事件,我认为我可以捕获该事件,然后从那里限制导航器的大小。但它并没有真正按预期工作。我似乎能够限制绘制数据的 x 大小。但是导航器根本不遵循绘制数据的大小。我在这里错过了什么吗?我怎样才能让它正常工作?理想情况下,导航器将在特定大小上保持固定大小。有可能实现吗?
这里是 jsfiddle:
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
}]
});
});
我改变了这一点。我没有设置导航器的最大尺寸,而是限制用户完全改变它的尺寸。
我的想法来自 this post。
只需进行两处更改:
- 空白 drawHandle 函数
Highcharts.Scroller.prototype.drawHandle = function () {};
注释掉几行:
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) {
总的来说很干净。
我有一个时间序列很长的应用程序,我想限制导航器的最大尺寸。我在文档中找到了 afterSetExtremes 事件,我认为我可以捕获该事件,然后从那里限制导航器的大小。但它并没有真正按预期工作。我似乎能够限制绘制数据的 x 大小。但是导航器根本不遵循绘制数据的大小。我在这里错过了什么吗?我怎样才能让它正常工作?理想情况下,导航器将在特定大小上保持固定大小。有可能实现吗?
这里是 jsfiddle:
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
}]
});
});
我改变了这一点。我没有设置导航器的最大尺寸,而是限制用户完全改变它的尺寸。
我的想法来自 this post。
只需进行两处更改:
- 空白 drawHandle 函数
Highcharts.Scroller.prototype.drawHandle = function () {};
注释掉几行:
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) {
总的来说很干净。