How to bring specific curves in-front in ZedGraph
c#, curves, plot, zedgraph
Solution
The GraphPane contains a CurveList property, and the CurveList class is a subclass of `List<CurveItem>`. If you set the CurveItem.Tag property for each curve that you draw, I believe you should be able to sort the curve items by using the `CurveList.Sort(IComparer<CurveItem>)` method and using the `Tag` to represent the sorting order.
UPDATE JUNE 19
Simple example: two lines, the blue `line2` with `line2.Tag = 2` and the red `line1` with `line1.Tag = 1`. In the initialization `line2` is added first to the graph pane, so it will be displayed on top.
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();
}
To sort, first implement a class that implements `IComparer<CurveItem>`, and that sorts the curve items in ascending order based on the numerical value of the `CurveItem` `Tag` property:
class CurveItemTagComparer : IComparer<CurveItem>
{
public int Compare(CurveItem x, CurveItem y)
{
return ((int)x.Tag).CompareTo((int)y.Tag);
}
}
To perform re-sorting and update the graph, implement the following event handler for the Sort button:
void SortButtonClick(object sender, EventArgs e)
{
_graph.GraphPane.CurveList.Sort(new CurveItemTagComparer());
_graph.Refresh();
}
Now, when clicking the Sort button, the curves will be sorted such that the curve with the lowest tag value, i.e. `line1`, will instead be drawn on top. Additionally, note that the curve order in the legend is changed along.
Problem
I have two curves on the zedgraph control, after plotting both the 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 managed to plot the two curves as power line curve over the threshold line curve. Now my questions is, if I want to bring any one of the curve in front....Is there any method available(ex: bringittoFront()....)...? Thanks a lot for your time ....:)