1

Im new to android and very new to android plot. Can you point me to an example that uses FixedSizeEditableXYSeries?

My goal is to create a streaming plot that shows the latest sensor readings in an android app.

Thanks

===================Update - following discussion with @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);
    }
}

This gives me a nice graph but no line. It doesnt look like the plot is being updates as new data is filling the FixedSizeEditableXYSeries.

MadProgrammer
  • 423
  • 1
  • 5
  • 17
  • how are you wanting the show the stream of data? there are two popular approaches: scrolling, where data continuously moves across the screen left to right or right to left (a CPU usage monitor for example) and for lack of a better name, scanning where data fills the screen from left to right until the screen end is reached at which point it resets back to the screen start, overwriting the previous data at each index as it goes. (An ECG is a good example of this) – Nick Feb 17 '17 at 14:18
  • @Nick, I would like to move the data continuously from left to right on screen (I think you refer to this as scrolling here). I will now update the question with my existing code so you can see more. – MadProgrammer Feb 17 '17 at 21:29

1 Answers1

1

If you want scrolling behavior then FixedSizeEditableXYSeries would be the wrong choice; as your data scrolls you're essentially enqueueing the newest value and dequeuing the oldest value; a linked list type structure would be a better choice.

You can either implement XYSeries and back it with any suitable data structure you prefer, or you can use SimpleXYSeries, which already supports queue operations a la removeFirst() and addLast(...). There's a great example of of a dynamic scrolling plot in the demo app: OrientationSensorExampleActivity. Lines 235-245 show the specific actions mentioned above.

Nick
  • 8,181
  • 4
  • 38
  • 63