本文介绍了放大海图时如何启用y轴平移?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我放大图表时,我想在Y轴上移动现在,我可以在缩放时在X轴上移动
I want to move in Y-Axis while i am in zoom in charts Right now i am able to move on X-Axis while zooming
下面是平移代码
chart: {
renderTo: 'container1',
type: 'column',
zoomType: 'xy',
panning: true,
panKey: 'shift',}
任何帮助将不胜感激
推荐答案
可能的解决方案:
-
您可以在Highstock中设置垂直滚动条.
You could set vertical scrollbars in Highstock.
yAxis: {
scrollbar: {
enabled: true
}
},
文章: http://www.highcharts.com/news/224个滚动条用于任何轴
- 使用基于插件的包装器代码(包含在下面)由 Barbara 建议,它允许缩放(xy)和平移(xy).
- Use a wrapper code (included below) based on the plugin suggested by Barbara that allows zooming (xy) and panning (xy).
包装器代码:
(function (H) {
H.wrap(H.Chart.prototype, 'pan', function (proceed) {
var chart = this,
hoverPoints = chart.hoverPoints,
doRedraw,
e = arguments[1],
each = H.each;
// remove active points for shared tooltip
if (hoverPoints) {
each(hoverPoints, function (point) {
point.setState();
});
}
var mousePosX = e.chartX,
mousePosY = e.chartY,
xAxis = chart.xAxis[0],
yAxis = chart.yAxis[0],
startPosX = chart.mouseDownX,
startPosY = chart.mouseDownY,
halfPointRangeX = (xAxis.pointRange || 0) / 2,
halfPointRangeY = (yAxis.pointRange || 0) / 2,
extremesX = xAxis.getExtremes(),
newMinX = xAxis.toValue(startPosX - mousePosX, true) + halfPointRangeX,
newMaxX = xAxis.toValue(startPosX + chart.plotWidth - mousePosX, true) - halfPointRangeX,
extremesY = yAxis.startingExtremes,
newMaxY = yAxis.toValue(startPosY - mousePosY, true) + halfPointRangeY,
newMinY = yAxis.toValue(startPosY + chart.plotHeight - mousePosY, true) - halfPointRangeY;
if (xAxis.series.length && newMinX > Math.min(extremesX.dataMin, extremesX.min) && newMaxX < Math.max(extremesX.dataMax, extremesX.max) && newMinY > Math.min(extremesY.dataMin, extremesY.min) && newMaxY < Math.max(extremesY.dataMax, extremesY.max)) {
xAxis.setExtremes(newMinX, newMaxX, false, false, {
trigger: 'pan'
});
yAxis.setExtremes(newMinY, newMaxY, false, false, {
trigger: 'pan'
});
doRedraw = true;
}
chart.mouseDownX = mousePosX;
chart.mouseDownY = mousePosY;// set new reference for next run
if (doRedraw) {
chart.redraw(false);
}
});
}(Highcharts));
应该在图表的回调或图表的加载事件中设置起始极点:
Starting extremes should be set in chart's callback or load event of a chart like:
}, function(chart){
chart.yAxis[0].startingExtremes = chart.yAxis[1].getExtremes();
});
演示: http://jsfiddle.net/Lxjqed02/3/
这篇关于放大海图时如何启用y轴平移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!