如何在Zedgraph中同步所选窗格的X轴?

时间:2013-11-27 11:16:01

标签: c# zedgraph

我正在尝试在Zedgraph中同步所选窗格的X轴,

目前我已经三个窗格:

enter image description here

在以下属性的帮助下,我可以同步所有可用窗格的X轴:

zedGraphControl1.IsSynchronizeXAxes = true;

但我想同步 Pane-1& Pane-3 ,有可能吗?

非常感谢您的时间...... :)

1 个答案:

答案 0 :(得分:2)

  1. 列表项
  2. 是的。

    基本上,您必须挂钩到ZoomEvent,然后使用FindPane捕获已经平移或缩放的窗格,将其Scale Min和Max属性应用于其他属性,然后执行AxisChange如果某些其他“缩放”属性设置为Auto

    假设您要排除的GraphPane对象为excludedGraphPane

    void zedGraphControl1_ZoomEvent(ZedGraph.ZedGraphControl z, ZedGraph.ZoomState oldState, ZedGraph.ZoomState newState)
    {
        GraphPane pane;
    
        using (var g = z.CreateGraphics())
            pane = z.MasterPane.FindPane(z.PointToClient(MousePosition));
    
        // The excludedGraphPane has to remain independant
        if (pane == null || pane == excludedGraphPane)
            return;
    
        foreach (var gp in z.MasterPane.PaneList)
        {
            if (gp == pane || gp == excludedGraphPane)
                continue;
    
            gp.XAxis.Scale.Min = pane.XAxis.Scale.Min;
            gp.XAxis.Scale.Max = pane.XAxis.Scale.Max;
            gp.AxisChange(); // Only necessary if one or more scale property is set to Auto.
        }
    
        z.Invalidate();
    }
    

    当然,由于现在手动完成同步,您需要设置

    zedGraphControl1.IsSynchronizeXAxes = false;