2017-02-16 1 views
1

Im android and new에 매우 새로운 기능입니다. 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

어떻게 쇼에 데이터 스트림을 원하십니까? 스크롤링은 데이터가 왼쪽에서 오른쪽 또는 오른쪽에서 왼쪽으로 연속적으로 이동하는 스크롤링 (예 : CPU 사용률 모니터)과 더 나은 이름이없는 경우 데이터가 화면을 왼쪽에서 오른쪽으로 채울 때까지 스캔합니다. 화면 끝에 도달하면 화면 시작으로 다시 재설정되고 각 색인에서 이전 데이터를 덮어 씁니다. (ECG는 이것의 좋은 예입니다.) – Nick

+0

@ 닉, 저는 계속 화면에서 왼쪽에서 오른쪽으로 데이터를 이동하고 싶습니다. (여기서는 스크롤이라고 부릅니다). 이제 기존 코드로 질문을 업데이트하여 더 많이 볼 수 있습니다. – MadProgrammer

답변

1

스크롤 동작을 원할 경우 FixedSizeEditableXYSeries은 잘못된 선택입니다. 데이터가 스크롤 될 때 본질적으로 가장 새로운 값을 큐잉하고 가장 오래된 값을 추출합니다. 연결된 목록 유형 구조가 더 나은 선택이 될 것입니다.

당신은 XYSeries를 구현하고 원하는 임의의 적절한 데이터 구조를 백업하거나 이미 removeFirst()addLast(...) 라 큐 작업을 지원하는 SimpleXYSeries를 사용 할 수 있습니다. 데모 앱에는 동적 스크롤 플롯의 좋은 예가 있습니다 : OrientationSensorExampleActivity. 라인 235-245은 위에서 언급 한 특정 작업을 보여줍니다.