How to cast specific curves in ZedGraph

I have two curves on a zebra control, after plotting both curves ...

PointPairList thresholdList = new PointPairList();
PointPairList powerList = new PointPairList();

private void plotPower()
{
        // Create an object to access ZedGraph Pane
        GraphPane pane = zedGraphControl1.GraphPane;            
        LineItem thresholdLine = new LineItem("thresholdLine");
        LineItem powerLine = new LineItem("powerLine");

        // Set the Threshold Limit
        double thresoldLimit = Convert.ToDouble(numAnalysisThreshold2.Value);

        // Points
        double[] x = new double[]{0, pane.XAxis.Scale.Max};
        double[] y = new double[]{thresoldLimit, thresoldLimit};

        // Set the threshold line curve list
        thresholdList.Add(x, y); 

        // Set the Power Line curve list
        powerdList.Add(XData, YData);

        // Add Curves
        thresholdLine = pane.AddCurve("", thresholdList, Color.Red, SymbolType.None);
        powerLine = pane.AddCurve("", powerList, Color.Red, SymbolType.None);

        // Refresh Chart
        this.Invalidate();
        zedGraphControl1.Refresh();
}

From the above code, I was able to build two curves in the form of a power line curve along a threshold line curve.

Now my questions: if I want to output any of the curve in front ... Is there any method (for example: bringittoFront () ....) ...?

Thanks so much for your time .... :)

+5
source share
3 answers

GraphPane CurveList , CurveList List<CurveItem>. CurveItem.Tag , , , CurveList.Sort(IComparer<CurveItem>) Tag .

19

: , line2 line2.Tag = 2 line1 line1.Tag = 1. line2 , .

void GraphInit()
{
    var line2 = _graph.GraphPane.AddCurve("Second", 
        new[] { 0.1, 0.5, 0.9 }, new[] { 0.1, 0.5, 0.1 }, Color.Blue);
    line2.Tag = 2;

    var line1 = _graph.GraphPane.AddCurve("First", 
        new[] { 0.1, 0.5, 0.9 }, new[] { 0.1, 0.5, 0.9 }, Color.Red);
    line1.Tag = 1;

    _graph.Refresh();
}

Initial display before sorting

, IComparer<CurveItem>, CurveItem Tag:

class CurveItemTagComparer : IComparer<CurveItem>
{
    public int Compare(CurveItem x, CurveItem y)
    {
        return ((int)x.Tag).CompareTo((int)y.Tag);
    }
}

, :

void SortButtonClick(object sender, EventArgs e)
{
    _graph.GraphPane.CurveList.Sort(new CurveItemTagComparer());
    _graph.Refresh();
}

, "", , , .. line1, . , , .

Graph after Sort button is clicked

+8

. Move() CurveList. , :

zedGraphControl1.GraphPane.CurveList.Move(index,relativePos)

relativePos -1 , 1 . , (, -999). , .

+5

And for those who need it, this is the code for the IComparer class for vb.net:

    Public Class CurveItemTagComparer
    Implements IComparer(Of CurveItem)
    Function Compare(ByVal x As ZedGraph.CurveItem, ByVal y As ZedGraph.CurveItem) As Integer _
    Implements System.Collections.Generic.IComparer(Of CurveItem).Compare
        Return CInt(x.Tag).CompareTo(CInt(y.Tag))
    End Function
End Class

Giovanni

+3
source

All Articles