San*_*VEE 5 c# plot zedgraph 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();
}
Run Code Online (Sandbox Code Playgroud)
从上面的代码中,我设法将两条曲线绘制为超过阈值线曲线的电源线曲线.
现在我的问题是,如果我想把前面任何一条曲线带到前面......有没有任何方法可用(例如:bringittoFront()....)......?
非常感谢您的时间.... :)
该GraphPane包含CurveList属性和CurveList类的子类List<CurveItem>
.如果为绘制的每条曲线设置CurveItem.Tag属性,我相信您应该能够使用该CurveList.Sort(IComparer<CurveItem>)
方法对曲线项进行排序,并使用它Tag
来表示排序顺序.
更新6月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();
}
Run Code Online (Sandbox Code Playgroud)
要进行排序,首先要实现一个实现的类IComparer<CurveItem>
,然后根据CurveItem
Tag
属性的数值按升序对曲线项进行排序:
class CurveItemTagComparer : IComparer<CurveItem>
{
public int Compare(CurveItem x, CurveItem y)
{
return ((int)x.Tag).CompareTo((int)y.Tag);
}
}
Run Code Online (Sandbox Code Playgroud)
要执行重新排序和更新图形,请为" 排序"按钮实现以下事件处理程序:
void SortButtonClick(object sender, EventArgs e)
{
_graph.GraphPane.CurveList.Sort(new CurveItemTagComparer());
_graph.Refresh();
}
Run Code Online (Sandbox Code Playgroud)
现在,当单击" 排序"按钮时,将对曲线进行排序,使得具有最低标记值的曲线(即line1
,将在顶部绘制).此外,请注意图例中的曲线顺序会一直更改.
归档时间: |
|
查看次数: |
5306 次 |
最近记录: |