我已经解决了这个问题(现在?),通过调整y轴相对于彼此的范围,所以每个轴的正负比例是相同的。下面的代码似乎对我的用例工作正常。
function zoom(minDate, maxDate) {
minFirst = g.yAxisRanges()[0][0]
maxFirst = g.yAxisRanges()[0][1] || 1
minSecond = g.yAxisRanges()[1][0]
maxSecond = g.yAxisRanges()[1][1] || 1
if (minFirst >= 0 && minSecond >= 0) {
// setting both to zero will align zero at bottom
minFirst = secondFirst = 0;
} else {
// calculate ratio (negative part : positive part)
var ratioFirst = - minFirst/maxFirst
var ratioSecond = - minSecond/maxSecond
if (minFirst >= 0 || ratioFirst < ratioSecond) {
minFirst = - maxFirst * ratioSecond
} else {
minSecond = - maxSecond * ratioFirst
}
}
g.updateOptions({
axes: {
y: { valueRange: [minFirst, maxFirst] },
y2: { valueRange: [minSecond, maxSecond] }
}
});
}
function resetY() {
g.updateOptions({
valueRange: null,
axes: {
y: { valueRange: [null, null] },
y2: { valueRange: [null, null] }
}
});
}
g.updateOptions({
zoomCallback: function(minDate, maxDate, yRanges) {
resetY();
g.ready(function() {
zoom(minDate, maxDate)
})
}
})