ZedGraph - 添加阈值线

时间:2011-05-14 13:52:37

标签: c# zedgraph

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

我该怎么做?

我目前这样做是为了在自己的tabPage中显示perfcounter:

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;

1 个答案:

答案 0 :(得分:7)

您可以通过向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);