2012-11-24 59 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將根據數據對您的軸類型。