Is there a way to dynamically add data to the original series in a chart (right now, I'm trying to add new data to a line chart when panned but the question is broader)? Adding a new series works all right, I can create a new XYSeries
and even reuse the XYSeriesRenderer
to have the same display. When added to the chart, it will display but, obviously, as a new series, meaning that it won't join seamlessly with the previous data and displayed values above the line will be duplicated.
If I keep the dataset, the series renderer and the series itself and try to re-use them later, I get a seemingly endless loop when I try to series.add(x, y)
my new values, the program never returns. I also tried to dataset.removeSeries(series)
before adding the new values and dataset.addSeries(series)
again but in vain.
Update with code:
The chart is set up like this:
renderer = new XYMultipleSeriesRenderer();
renderer.setAntialiasing(true);
...
renderer.setZoomEnabled(false, false);
dataset = new XYMultipleSeriesDataset();
seriesRenderer = new XYSeriesRenderer();
seriesRenderer.setColor(chartColor);
...
seriesRenderer.setChartValuesTextSize(...);
renderer.addSeriesRenderer(seriesRenderer);
series = new XYSeries("");
...
series.add(x, y);
...
dataset.addSeries(series);
Called in PanListener.panApplied:
dataset.removeSeries(series);
...
series.add(x, y);
...
dataset.addSeries(series);