Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery flot图表两个y轴,相同的零位_Javascript_Jquery_Flot_Yaxis - Fatal编程技术网

Javascript jQuery flot图表两个y轴,相同的零位

Javascript jQuery flot图表两个y轴,相同的零位,javascript,jquery,flot,yaxis,Javascript,Jquery,Flot,Yaxis,我希望第二个y轴的零位置与第一个y轴相同 有没有内置的方法来实现这一点,或者我必须使用Axis min/max 我有动态数据(当用户选择东西时,很多图表刷新)以正负值显示,所以y轴上总是有一个零刻度 两个y轴的缩放和值不同,这是正常的,但零位置必须在完全相同的像素位置(在一条水平线上)。 如何做到这一点 我知道“alignTicksWithAxis”,但正如你所见,这不是我想要的 我编写了一个小js脚本,在图表显示后修剪零位,如果我将axis min/max设置为滑动轴,则效果很好(零同步),但

我希望第二个y轴的零位置与第一个y轴相同

有没有内置的方法来实现这一点,或者我必须使用Axis min/max

我有动态数据(当用户选择东西时,很多图表刷新)以正负值显示,所以y轴上总是有一个零刻度

两个y轴的缩放和值不同,这是正常的,但零位置必须在完全相同的像素位置(在一条水平线上)。 如何做到这一点

我知道“alignTicksWithAxis”,但正如你所见,这不是我想要的

我编写了一个小js脚本,在图表显示后修剪零位,如果我将axis min/max设置为滑动轴,则效果很好(零同步),但这样一些点会从画布中消失

所以我只需要设置一个比率的最小值或最大值,但在两个零位之间总是有10-20px的差值

EDIT1:

PlotOptions po=simplePlot.getPlotOptions();
axis1=simplePlot.GetAxis().getY(1),axis2=simplePlot.GetAxis().getY(2);
AbstractAxisOptions ao1=po.getYAxesOptions().getAxisOptions(1);
AbstractAxisOptions ao2=po.getYAxesOptions().getAxisOptions(2);
双yMin1=axis1.getMinimumValue(),yMax1=axis1.getMaximumValue(),yDiff1=yMax1-yMin1;
双yMin2=axis2.getMinimumValue(),yMax2=axis2.getMaximumValue(),yDiff2=yMax2-yMin2;
double diffPx=(axis2.p2c(0)-axis1.p2c(0))/2.0;//px中两个零点之间的差值除以2,axis1将从顶部压缩,axis2将从底部压缩

if(diffpx)请展示你的作品,你到目前为止写了什么代码?我添加了我的代码,实际上这是gwt和gflot。请展示你的作品,你到目前为止写了什么代码?我添加了我的代码,实际上这是gwt和gflot。
PlotOptions po = simplePlot.getPlotOptions();
Axis axis1 = simplePlot.getAxes().getY(1), axis2 = simplePlot.getAxes().getY(2);
AbstractAxisOptions ao1 = po.getYAxesOptions().getAxisOptions(1);
AbstractAxisOptions ao2 = po.getYAxesOptions().getAxisOptions(2);
double yMin1 = axis1.getMinimumValue(), yMax1 = axis1.getMaximumValue(), yDiff1 = yMax1-yMin1;
double yMin2 = axis2.getMinimumValue(), yMax2 = axis2.getMaximumValue(), yDiff2 = yMax2-yMin2;
double diffPx = (axis2.p2c(0) - axis1.p2c(0))/2.0; // diff between the two zero points in px, divided by 2, axis1 will be compressed from the top, axis2 from bottom
if (diffPx<0) { // in this case change axis1 vars with axis2 vars
    diffPx=-diffPx;
    AbstractAxisOptions tAO=ao1; ao1=ao2; ao2=tAO;
    Axis tAX = axis1; axis1=axis2; axis2=tAX;
}
double diff1 = axis1.c2p(axis1.p2c(0)-diffPx); // axis1 zero pos must moved by this value
double diff2 = axis2.c2p(axis2.p2c(0)-diffPx); // axis2 zero pos must moved by this value

// calculate ratio values to compress the axes
double bottomRat1 = -yMin1 / yDiff1; // bottom part of axis1 (below zero) e.g. 1/3
double bottomRatNew1 = (-yMin1-diff1) / yDiff1; // same, but when compressed (with diff1)
double fullRat1 = bottomRat1 / bottomRatNew1; // ratio of original and compressed axis
double yDiffNew1 = yDiff1 / fullRat1; // the new axis1 length
double diffReal1 = yDiff1 - yDiffNew1; // the difference between the original and the new axis length (this is the value by which the axis must be compressed)

// same calculation for axis2 (but for the top part)
double topRat2 = yMax2 / yDiff2;
double topRatNew2 = (yMax2-diff2) / yDiff2;
double fullRat2 = topRat2 / topRatNew2;
double yDiffNew2 = yDiff2 / fullRat2;
double diffReal2 = yDiff2 - yDiffNew2;

boolean slide = false; // if true then axes slide (not compress) and zero positions will be in one line (this is the goal), but some points get out of the canvas
if (slide) {
    ao1.setMaximum(yMax1 + diff1);ao1.setMinimum(yMin1 + diff1);
    ao2.setMaximum(yMax2 - diff2);ao2.setMinimum(yMin2 - diff2);
} else {
// axes will be compressed (axis1 from the top, axis2 from the bottom), by the calculated values
// here I have some 10-30 px extra gap, why?
    ao1.setMaximum(yMax1 + diffReal1);ao1.setMinimum(yMin1);
    ao2.setMaximum(yMax2);ao2.setMinimum(yMin2 - diffReal2);
}
simplePolt.redraw();