[英]How to bring specific curves in-front in ZedGraph
I have two curves on the zedgraph control, after plotting both the curves... 在绘制两条曲线后,我在zedgraph控件上有两条曲线......
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()....)...? 现在我的问题是,如果我想把前面任何一条曲线带到前面......有没有任何方法可用(例如:bringittoFront()....)......?
Thanks a lot for your time ....:) 非常感谢您的时间.... :)
The GraphPane contains a CurveList property, and the CurveList class is a subclass of List<CurveItem>
. 所述GraphPane包含CurveList属性和CurveList类是的一个子类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. 如果为绘制的每条曲线设置CurveItem.Tag属性,我相信您应该能够使用CurveList.Sort(IComparer<CurveItem>)
方法对曲线项进行排序,并使用Tag
来表示排序顺序。
UPDATE JUNE 19 更新6月19日
Simple example: two lines, the blue line2
with line2.Tag = 2
and the red line1
with line1.Tag = 1
. 简单示例:两行,蓝色line2
, line2.Tag = 2
,红色line1
, line1.Tag = 1
。 In the initialization line2
is added first to the graph pane, so it will be displayed on top. 在初始化中, 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();
}
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: 要进行排序,首先要实现一个实现IComparer<CurveItem>
,然后根据CurveItem
Tag
属性的数值按升序对曲线项进行排序:
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, ie line1
, will instead be drawn on top. 现在,当单击“ 排序”按钮时,将对曲线进行排序,使得具有最低标记值的曲线(即line1
)将被绘制在顶部。 Additionally, note that the curve order in the legend is changed along. 此外,请注意图例中的曲线顺序会一直更改。
There is a very easy way. 有一种非常简单的方法。 Use the Move()
method in the CurveList
class. 使用CurveList
类中的Move()
方法。 For example in: 例如:
zedGraphControl1.GraphPane.CurveList.Move(index,relativePos)
setting relativePos
to -1
will move the object one position earlier in the list, while 1
will move it one position later. 将relativePos
设置为-1
会将对象移动到列表中较早的位置,而1
将稍后移动一个位置。 To move an item to the beginning of the list, use a large negative value (such as -999
). 要将项目移动到列表的开头,请使用较大的负值(例如-999
)。 To move it to the end of the list, use a large positive value. 要将其移动到列表的末尾,请使用较大的正值。
And, for who needs it, this is the code for the IComparer class for vb.net: 而且,对于谁需要它,这是vb.net的IComparer类的代码:
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 乔瓦尼
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.