在Zedgraph上绘制传入的串行数据,X轴从00:00开始

时间:2014-02-19 10:13:08

标签: c# zedgraph

我能够用当前时间绘制串行数据。假设我给出myPane.XAxis.Scale.Min = 0;和一些最大值,我如何让它们反映“list.add(...,value);”

“......”是我无法想象应该通过什么。我使用以下代码为HH:mm:ss。但是我需要X轴从00:00开始直到5分钟。

myPane.XAxis.Scale.MaxAuto = true;
myPane.XAxis.Scale.MinAuto = true;
myPane.XAxis.Type = AxisType.Date;
myPane.XAxis.Scale.Format = "HH:mm:ss";
myPane.Legend.Position = ZedGraph.LegendPos.TopCenter;

DateTime now = new DateTime();
now = DateTime.Now; double timestamp = new XDate(now);
list.Add(timestamp, f);

我很感激你的建议

1 个答案:

答案 0 :(得分:1)

我不知道它对你有帮助,但这是我的实时数据绘图代码。

/*Initial pane settings*/
pane.XAxis.Type = AxisType.Date;
pane.XAxis.Scale.Format = "dd/MM/yy\nH:mm:ss";
pane.XAxis.Scale.Min = (XDate)(DateTime.Now);
//Shows 25 seconds interval.
pane.XAxis.Scale.Max = (XDate)(DateTime.Now.AddSeconds(25));
pane.XAxis.Scale.MinorUnit = DateUnit.Second;
pane.XAxis.Scale.MajorUnit = DateUnit.Minute;
pane.XAxis.MajorTic.IsBetweenLabels = true;
pane.XAxis.MinorTic.Size = 5;

/*Real time plotting*/
XDate time = new XDate(DateTime.Now.ToOADate());
LineItem curve= curve= myPane.CurveList[0] as LineItem;
IPointListEdit list = list = curve.Points as IPointListEdit;
list.Add(time,data);
//Scale pane if current time is greater than the initial xScale.Max
Scale xScale = zgcMasterPane.MasterPane.PaneList[0].XAxis.Scale;
if (time.XLDate > xScale.Max)
{
  xScale.Max = (XDate)(DateTime.Now.AddSeconds(5));
  xScale.Min = (XDate)(DateTime.Now.AddSeconds(-20));
}