0

I want to display Battery Level in dynamic graph using android plot. Static graph is working fine whenever am dealing with DB [fetching the data from DB and displaying in graph]. But for real time dynamic graph am facing issues i.e. Using Broadcast receiver am able to get the battery level changes, but same time I want to update/refresh the existing graph which is displaying to the user without recreating the activity. For updating the graph am using the below code

if (plot != null) {
    plot.addListener(new PlotListener() {
    @Override
    public void onBeforeDraw(
        @SuppressWarnings("rawtypes") Plot arg0, Canvas arg1) {
    }
        @Override
    public void onAfterDraw(
        @SuppressWarnings("rawtypes") Plot arg0, Canvas arg1) {
        plot.clear();
        plot.redraw();
    }
    });
}

Can anybody please help me how to resolve this issue or some example to deal with this issue.

1 Answers1

0

It should be as simple as updating your Series instances to reflect the data you want displayed and then invoking plot.redraw(). If you are using an instance of SimpleXYSeries then you've got methods that let you modify arbitrary elements by index as well as standard dequeue operations. You don't want to invoke plot.clear() every time this happens.

If for example your goal is to display the battery level over the last n seconds, you would add each new sample to the end of the series and remove one from the beginning. (Or vice-versa if you wish for it to scroll in the opposite direction)

Nick
  • 8,181
  • 4
  • 38
  • 63