The issue I have is when using two Y-axes (y1 and y2), wherein the y1 value is: (min,max) = (zero,positive) and the y2 value (min, max) = (negative, positive), in such case, the zero marking of y1 coincides with the max (negative) value of the y2 ax开发者_开发问答is (through the x-axis), that is the problem since I want zero point of both y-axis to flush together.
If I knew the value of min and max for both y-axes then this problem could be fixed easily, but I only know whether the range starts from positive or negative value, not the value itself.
Note that this problem is not there when both y-axes have values (data points) above zero. They automatically align such that both their zero points passes through the x-axis.
I managed to do so by fixing the proportion between axis:
public void SetY1Y2CommonZero()
{
AxisChange();
ZedGraph.Scale source, dest;
if (GraphPane.YAxis.Scale.Min != 0)
{
source = GraphPane.YAxis.Scale;
dest = GraphPane.Y2Axis.Scale;
}
else if (GraphPane.Y2Axis.Scale.Min != 0)
{
source = GraphPane.Y2Axis.Scale;
dest = GraphPane.YAxis.Scale;
}
else
{
return;
// do nothing - both axis have 0 on min...
}
double proportion = source.Max / source.Min;
// we want to ENLARGE the other axis accordingly:
if (proportion * dest.Min > dest.Max)
dest.Max = proportion * dest.Min;
else
dest.Min = dest.Max / proportion;
}
精彩评论