【问题标题】:How to change ZedGraph Y axis order?如何更改 ZedGraph Y 轴顺序?
【发布时间】:2013-11-17 19:23:36
【问题描述】:

我有一个带有多个 Y 轴的 ZedGraph 控件,我希望允许用户更改 Y 轴的显示顺序。

不幸的是,GraphPaneYAxisList 对象上没有 Move 方法,就像它存在于 CurveList 上一样。

YAxisList 上的索引器是只读的。我不能使用the good old swap snippet 来交换列表中的轴。

我该如何继续?

【问题讨论】:

    标签: c# zedgraph


    【解决方案1】:

    我实现了一个扩展方法,灵感来自CurveListMove 方法。

    陷阱是现有曲线的 Y 轴索引需要相应更新。

    public static int Move(this YAxisList list, GraphPane pane, int index, int relativePos)
    {
        if (index < 0 || index >= list.Count)
            return -1;
    
        var axis = list[index];
        list.RemoveAt(index);
    
        var newIndex = index + relativePos;
    
        if (newIndex < 0)
            newIndex = 0;
        if (newIndex > list.Count)
            newIndex = list.Count;
    
        list.Insert(newIndex, axis);
    
        foreach (var curve in pane.CurveList)
            if (curve.YAxisIndex == newIndex)
                curve.YAxisIndex = index;
            else if (curve.YAxisIndex == index)
                curve.YAxisIndex = newIndex;
    
        return newIndex;
    }
    

    【讨论】:

      猜你喜欢
      • 2018-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多