Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <a href="http://zedgraph.sourceforge.net/documentation/html/T_ZedGraph_GraphPane.htm" rel="noreferrer">GraphPane</a> contains a <a href="http://zedgraph.sourceforge.net/documentation/html/P_ZedGraph_GraphPane_CurveList.htm" rel="noreferrer">CurveList</a> property, and the <a href="http://zedgraph.sourceforge.net/documentation/html/T_ZedGraph_CurveList.htm" rel="noreferrer">CurveList</a> class is a subclass of <code>List&lt;CurveItem&gt;</code>. If you set the <a href="http://zedgraph.sourceforge.net/documentation/html/F_ZedGraph_CurveItem_Tag.htm" rel="noreferrer">CurveItem.Tag</a> property for each curve that you draw, I believe you should be able to sort the curve items by using the <code>CurveList.Sort(IComparer&lt;CurveItem&gt;)</code> method and using the <code>Tag</code> to represent the sorting order.</p> <p><strong>UPDATE JUNE 19</strong></p> <p>Simple example: two lines, the blue <code>line2</code> with <code>line2.Tag = 2</code> and the red <code>line1</code> with <code>line1.Tag = 1</code>. In the initialization <code>line2</code> is added first to the graph pane, so it will be displayed on top.</p> <pre><code>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(); } </code></pre> <p><img src="https://i.stack.imgur.com/lI4KM.png" alt="Initial display before sorting"></p> <p>To sort, first implement a class that implements <code>IComparer&lt;CurveItem&gt;</code>, and that sorts the curve items in ascending order based on the numerical value of the <code>CurveItem</code> <code>Tag</code> property:</p> <pre><code>class CurveItemTagComparer : IComparer&lt;CurveItem&gt; { public int Compare(CurveItem x, CurveItem y) { return ((int)x.Tag).CompareTo((int)y.Tag); } } </code></pre> <p>To perform re-sorting and update the graph, implement the following event handler for the <em>Sort</em> button:</p> <pre><code>void SortButtonClick(object sender, EventArgs e) { _graph.GraphPane.CurveList.Sort(new CurveItemTagComparer()); _graph.Refresh(); } </code></pre> <p>Now, when clicking the <em>Sort</em> button, the curves will be sorted such that the curve with the lowest tag value, i.e. <code>line1</code>, will instead be drawn on top. Additionally, note that the curve order in the legend is changed along.</p> <p><img src="https://i.stack.imgur.com/V9U3h.png" alt="Graph after Sort button is clicked"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload