flot 导航插件平移到 y 轴的末端

flot navigate plugin pan to the end of the yaxis

我想平移到 y 轴的末端,我可以调用 plot.pan({top: 100}),我只是不知道如何获取当前视图与 y 轴末端之间的像素距离.每个轴上都有函数c2p()和p2c(),分别是canvas-2-point和point-2-canvas,但是它们并没有真正告诉你得到的值是多少back 的意思,它的参考点是什么等等

帮忙?

要平移到轴的终点(或起点),您不需要知道当前位置是什么。只需获取以像素为单位的平移范围的完整高度(或宽度),然后平移该数量。当它到达声像范围的末端时,插件将自动停止。要获得完整的宽度(或高度),请使用:

var axis = plot.getAxes().yaxis; // for x axis change yaxis to xaxis
var amount = Math.abs(axis.datamax - axis.datamin)*axis.scale;
plot.pan({top: amount}); // for x axis change top to left / for other direction use negative amount

这是一个 fiddle 的完整示例(x 轴平移,但对 y 轴的作用相同)。