2012-11-24 60 views
1

鉴于缺少文档,我对这个库仍然很粗糙。DynamicDataDisplay ChartPlotter滚动水平轴

我有一个ChartPlotter对象,它实时显示数据,因为它是通过捕获设备中的数据捕获的。 我有一个调用每次我有新的数据来自设备的时间了以下事件:

private void OnRawDataChanged(object sender, RawDataChangedEventArgs e) 
    { 
     System.Diagnostics.Debugger.Log(0, "event", "event received from data manager\n"); 
     System.Diagnostics.Debugger.Log(0, "event", e.NewRawDataSet.Length + " tuples of data returned\n"); 

     var batchSize = e.NewRawDataSet.Length; 

     // Expected tuples of 2 values + 2 threshold values 
     Point[][] points = new Point[4][]; 

     for (int i = 0; i < 4; i++) 
     { 
      points[i] = new Point[batchSize]; 
     } 

     double period = 1.0/Properties.Settings.Default.SamplingRate; 

     for (int i = 0; i < batchSize; i++) 
     { 
      // Time is expressed in milliseconds 
      double t = e.NewRawDataSet[i].Time/1000.0; 

      points[0][i] = new Point(t, e.NewRawDataSet[i].Sensors[0]); 
      points[1][i] = new Point(t, e.NewRawDataSet[i].Sensors[1]); 
      points[2][i] = new Point(t, parentForm.PressureHisteresysOpen); 
      points[3][i] = new Point(t, parentForm.PressureHisteresysClose); 
     } 

     plotter.Dispatcher.Invoke(DispatcherPriority.Normal, 
      new Action(() => 
       { 
        sensor0.AppendMany(points[0]); 
        sensor1.AppendMany(points[1]); 
        pressureOpen.AppendMany(points[2]); 
        pressureClose.AppendMany(points[3]); 
       })); 
    } 

随着海图机的标准设置,图形将自动调整窗口。 我想水平轴自动向左滚动,只显示捕捉的最后10秒(例如)。有没有办法做到这一点?

谢谢

回答

2

要实现这一点,您必须修改plotter.ViewPort.Visible属性。这个属性接受一个DataRect对象,你用值构造一个矩形。每当您接收到新的数据时,您都必须重新计算此矩形,以便您的图形将滚动到视图。

这里是构建DataRect的例子:

 double yMin = 1; 
     double yMax = 10; 
     double xMin = 1; 
     double xMax = 10; 
     plotter.ViewPort.Visible = new DataRect(xMin, yMin, xMax - xMin, yMax - yMin); 

你分钟,MAXS将根据数据对您的轴类型。