2017-02-16 2 views
1

私はアンドロイドに新しいとアンドロイドプロットには非常に新しいです。 FixedSizeEditableXYSeriesを使用する例を教えてください。AndroidPlot FixedSizeEditableXYSeries使用方法

私の目標は、アンドロイドアプリで最新のセンサーの読みを表示するストリーミングプロットを作成することです。

おかげ

===================アップデート - @Nickと以下の議論=============== =====

public class MainActivity extends AppCompatActivity { 


    // Create the redrawer so that the plot is updated 
    private Redrawer redrawer; 

    // create the message receiver - data is received via broadcasts 
    private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() { 
     @Override 
     public void onReceive(Context context, Intent intent) { 
      // Get extra data included in the Intent 
      String message = intent.getStringExtra("CurrentHR"); 

      Log.d("ReceivedHR ",message); 

      // Now put the new data point at the end of the FixedSizeEditableXYSeries, move all data points by 1. 
      for (int index=0;index<9;index++){ 

       if(index<9){ 
        hrHistory.setY(hrHistory.getY(index+1),index); 
       }else{ 
        hrHistory.setY(Float.parseFloat(message),9); 
       } 
      } 


     } 
    }; 

    // create a few references 
    private XYPlot xyPlot; 
    private FixedSizeEditableXYSeries hrHistory; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_heart_rate); 

     // Now find the plot views 
     xyPlot = (XYPlot)findViewById(R.id.xyPlot); 

     // Declare the local broadcast manager 
     LocalBroadcastManager.getInstance(this).registerReceiver(
       mMessageReceiver, new IntentFilter("hrUpdate")); 


     // now put in some data 
     hrHistory = new FixedSizeEditableXYSeries("HR",10); 

     xyPlot.addSeries(hrHistory, new LineAndPointFormatter(Color.GREEN,Color.RED,null,null)); 
     xyPlot.setRangeBoundaries(40, 120, BoundaryMode.FIXED); 
     xyPlot.setDomainBoundaries(0, 20, BoundaryMode.FIXED); 
    } 

    @Override 
    protected void onResume(){ 
     super.onResume(); 


     // set a redraw rate of 1hz and start immediately: 
     redrawer = new Redrawer(xyPlot, 1, true); 
    } 
} 

これは私に素晴らしいグラフですが、行はありません。それは新しいデータがFixedSizeEditableXYSeriesを埋めるので、プロットが更新されているようには見えません。

+0

どのようにデータストリームを表示したいですか? 2つの一般的なアプローチがあります。スクロールは、データが画面の左から右または右から左へ連続的に移動する場合(たとえば、CPU使用率モニターなど)、より良い名前がない場合は、データが画面を左から右に画面の終わりに達すると、それは画面の開始に戻ってリセットされ、各インデックスの前のデータを上書きします。 (ECGはこれの良い例です) – Nick

+0

@Nick、私は画面上で左から右へ連続的にデータを移動したいと思っています(私はこれをここでスクロールすると言います)。私は今あなたの既存のコードで質問を更新し、より多くを見ることができます。 – MadProgrammer

答えて

1

スクロール動作をしたい場合は、FixedSizeEditableXYSeriesが間違った選択です。データがスクロールすると、基本的には最新の値がエンキューされ、最も古い値がデキューされます。リンクリストタイプの構造がより良い選択肢になります。

あなたはXYSeriesを実装し、あなたが好む任意の適切なデータ構造とそれをバックアップ、またはあなたがSimpleXYSeriesを使用することができ、すでにキュー操作ラremoveFirst()addLast(...)をサポートすることができます。デモアプリケーションに動的なスクロールプロットの素晴らしい例があります:OrientationSensorExampleActivity。ライン235-245は上記の特定のアクションを示しています。

関連する問題