我已經解決了這個問題(現在?),通過調整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)
})
}
})