ZedGraph - 添加阈值线

本文关键字:阈值 添加 ZedGraph | 更新日期: 2023-09-27 17:56:20

这可能很简单,但我无法弄清楚。我为每个操作系统性能计数器(Y->值,x->时间)都有一个线性图。现在,我想为阈值 Y 值添加一条水平直线,例如红色,以便它与实际数据一起显示在图表中。我已经知道每个计数器的阈值。

我该怎么做?

我目前这样做是为了在其自己的标签页中显示性能计数器:

Cursor = Cursors.WaitCursor;
var perfCounter = PerfDictValues.Value.First(pc => pc.Counter == counter);
var tPage = new TabPage((tabControl1.TabPages.Count + 1).ToString());
tPage.Tag = perfCounter;
tPage.Padding = new Padding { All = 8 };
var zedGraph = new ZedGraphControl();
zedGraph.Dock = DockStyle.Fill;
var graphPane = zedGraph.GraphPane;
graphPane.Title.Text = counter;
graphPane.XAxis.Title.Text = String.Format("Max: {0}, Min: {1}, Avg: {2}", perfCounter.Maxm, perfCounter.Min, perfCounter.Average);
var curve = graphPane.AddCurve(counter, perfCounter.PointList, Color.Blue, SymbolType.Diamond); //Want to add a threshold value from perfCounter.Threshold property
 graphPane.XAxis.Type = AxisType.Linear;
 graphPane.AxisChange();
 tPage.Controls.Add(zedGraph);
 tabControl1.TabPages.Add(tPage);
 tabControl1.SelectedTab = tPage;
 grpOutput.Visible = true;

ZedGraph - 添加阈值线

您可以通过在 GraphObj 列表中添加 LineObj 在图形上绘制一条简单的红线,即绘制一条水平线

double threshHoldY = 2;
LineObj threshHoldLine = new LineObj(
    Color.Red,
    graphPane.XAxis.Scale.Min,
    threshHoldY,
    graphPane.XAxis.Scale.Max,
    threshHoldY);
graphPane.GraphObjList.Add(threshHoldLine);