2

i presume it is pretty basic, but I can't find the solution. I have something like this:

public SimpleXYSeries historySeries;
historySeries = new SimpleXYSeries("something");

then in background thread I add some data to the series:

historySeries.addLast(newRoll, newAzimuth);

Question is, how can I easily just remove all the data entries from the series, when needed?

Right now I have something like:

public void initSeries() {
        historyPlot.removeSeries(historySeries);
        historySeries = null;
        historyPlot.clear();
        historySeries = new SimpleXYSeries("something");
        historyPlot.addSeries(historySeries, lpf);
    }

It works, but graph flickers when I do addSeries again.

EDIT:

I have resolved the issue by making my own version of SimpleXYSeries and added a method:

    public void removeXY() {
        lock.writeLock().lock();
        try {
            xVals.clear();
            yVals.clear();
        } finally {
            lock.writeLock().unlock();
        }
    }
netpork
  • 552
  • 7
  • 20

2 Answers2

0

I have always used clear() to remove the plot and never had the graph flicker. Are you trying this on just an emulator or also on a real device?

I also found these method:

historyPlot.getSeriesSet.removeAll(historySeries);
historyPlot.removeMarkers();

I am not sure if it will be any better for a flicker

buczek
  • 2,011
  • 7
  • 29
  • 40
  • I am testing it on a real device. The "flicker" thing I have solved since it was, of course, my fault, I extended LineAndPointFormatter and made some mistakes. The only solution for me was to make modified version of SimpleXYSeries, and add methods for clearing xVals and yVals. – netpork Oct 07 '13 at 08:50
  • Glad you figured out the issue. You should answer your own question and accept the answer so the question will be closed. – buczek Oct 08 '13 at 16:03
0

It is odd that there is no clear() or removeAll() function built into SimpleXYSeries. As you have already mentioned, the best fix is to modify the source code to add that functionality. However, for those that are averse to doing that, you can call removeLast() until all the entries are removed from the series. It's working fine for me thus far.

while (series.size() > 0) {
    series.removeLast();
}
andrei
  • 83
  • 7
  • 1
    A clear() method will be added in the next release of Androidplot, along with accessors to the underlying data lists to make it easier for those wishing to extend SimpleXYSeries to do so in the future :-) – Nick Aug 27 '16 at 22:53