这是我用来绘制离散图形的代码:
private void DrawHartleyGraph(double [] values, ZedGraphControl zed)
{
GraphPane pane = zed.GraphPane;
pane.CurveList.Clear();
pane.XAxis.Title.Text = "ν";
pane.YAxis.Title.Text = "H(ν)";
pane.Title.Text = "ДПХ";
PointPairList list = new PointPairList();
for (int i = 0; i < values.Length ; i++)
{
list.Add((double)i, values[i]);
}
LineItem myCurve = pane.AddCurve("H(ν) - ДПХ", list, Color.Blue, SymbolType.Circle);
myCurve.Line.IsVisible = false;
myCurve.Symbol.Fill.Color = Color.Blue;
myCurve.Symbol.Fill.Type = FillType.Solid;
myCurve.Symbol.Size = 4;
pane.XAxis.Scale.Min = 0;
pane.XAxis.Scale.Max = numOfCountsN;
pane.YAxis.Scale.Min = values.Min();
pane.YAxis.Scale.Max = values.Max();
pane.IsBoundedRanges = true;
zed.AxisChange();
zed.Invalidate();
}
我得到了这样的照片:
如何绘制从X轴开始到结束点的垂直线,表示函数的值?
这是找到的决定。您需要以这种方式修改for-cycle:
for (int i = 0; i < values.Length ; i++)
{
list.Add((double)i, values[i]);
LineObj vertLine = new LineObj(Color.Red, i, 0,
i, values[i]);
pane.GraphObjList.Add(vertLine);
}