2011-11-28 44 views
2

我可以成功放大的X只能隔着使用下面的代碼的所有地塊:重縮放X在ZedGraph

zg1.IsEnableHZoom = true; 
zg1.IsEnableVZoom = false; 
zg1.IsSynchronizeXAxes = true; 

foreach (GraphPane gp in zg1.MasterPane.paneList) 
{ 
    > //What code can I put here? 
} 

我的問題是,使用此代碼,Y軸保持在最大值和最小值基於數據的原始視圖。我希望Y軸自動縮放,以便最大和最小值僅基於由於x軸縮放(當然每個圖形窗格)而可見的數據。是否有一些命令或蠻力方法可用於上面顯示的for循環中的每個圖形窗格?提前謝謝任何人的幫助。

回答

0

我之前有同樣的問題,找不到檢查所有曲線點的方法。

我添加了一個事件處理程序到Paint事件來做到這一點,我敢肯定有一些方法可以優化。

事情是這樣的:

private void graph_Paint(object sender, PaintEventArgs e) 
    { 
    double min = Double.MaxValue; 
    double max = Double.MinValue; 

    CurveItem curve = graph.GraphPane.CurveList[0]; 
    for (int i = 0; i < curve.Points.Count; i++) 
    { 
     if (curve.Points[i].X > graph.GraphPane.XAxis.Scale.Min && 
      curve.Points[i].X < graph.GraphPane.XAxis.Scale.Max) 
     { 
     min = Math.Min(curve.Points[i].Y, min); 
     max = Math.Max(curve.Points[i].Y, max); 
     } 
    } 

    if (min != Double.MaxValue) 
    { 
     graph.GraphPane.XAxis.Scale.Min = min; 
     graph.GraphPane.XAxis.Scale.Max = max; 
    } 
    } 
1

可以在循環使用(假設X軸刻度MinAuto和MaxAuto都是假的)

foreach (GraphPane gp in zg1.MasterPane.paneList) 
{ 
    gp.YAxis.Scale.MinAuto = true; 
    gp.YAxis.Scale.MaxAuto = true; 

    // This will force ZedGraph to calculate the Min and the Max of the Y axis 
    // based on the X axis visible range 
    gp.IsBoundedRanges = true; 
} 

zg1.MasterPane.AxisChange();