0

I have a ZedGraph control with multiple Y axis, and I want to allow the user to change the order in which the Y axis are displayed.

Unfortunately there is no Move method on the YAxisList object of the GraphPane, like it exists on the CurveList.

The indexers on the YAxisList are readonly. I can not use the good old swap snippet to swap axis in the list.

How can I proceed ?

1 Answer 1

0

I implemented a extension method inspired by the Move method of the CurveList.

The trap is that the Y Axis Indexes of existing curves needs to be updated accordingly.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.