c# - 如何在 ZedGraph 中将特定曲线置于最前面

标签 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();
}

从上面的代码中,我设法将两条曲线绘制为电源线曲线超过阈值线曲线。

现在我的问题是,如果我想把任何一条曲线放在前面....有没有可用的方法(例如:bringittoFront()....)......?

非常感谢您的宝贵时间....:)

最佳答案

GraphPane包含 CurveList属性(property),和CurveList类是 List<CurveItem> 的子类.如果设置 CurveItem.Tag您绘制的每条曲线的属性,我相信您应该能够使用 CurveList.Sort(IComparer<CurveItem>) 对曲线项进行排序方法和使用 Tag表示排序顺序。

6 月 19 日更新

简单的例子:两条线,蓝色line2line2.Tag = 2和红色line1line1.Tag = 1 .在初始化line2首先添加到图形 Pane ,因此它将显示在顶部。

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

关于c# - 如何在 ZedGraph 中将特定曲线置于最前面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11103596/

相关文章:

Java:声音捕获和波形绘制

c# - ZedGraph 自定义图表

c# - 仅显示每个标签的刻度线

c# - 使用屏蔽文本框来验证输入

r - 创建密度图时出错

c# - 如何将对象分配给字段

r - text() 在 R 图中显示带下标的希腊字母

winforms - ZedGraph 中的工具提示不断刷新并使用大量 CPU

c# - 如何在 FireFox 运行时访问 FireFox 3 书签?

c# - 为具有大量依赖项的库创建包装器的正确方法