2011-01-13 82 views
2

我遇到的問題是當使用兩個Y軸(y1和y2),其中y1值爲:(min,max)=(零,正值)和y2值(最小,最大)=(負,正),在這種情況下,y1的零標記與y2軸的最大(負)值一致(通過x軸),這是問題,因爲我想要零兩個y軸的點一起齊平。ZedGraph v。5.15,多軸對齊

如果我知道兩個y軸的最小值和最大值,那麼這個問題可以很容易地解決,但我只知道範圍是從正值還是負值開始,而不是從值本身開始。

請注意,當兩個y軸的值(數據點)都大於零時,此問題不存在。它們自動對齊,使得它們的零點都穿過x軸。

回答

0

我設法做到通過固定軸之間的比例:

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; 
}