Android LineSeries animation on redraw and orientation change


#1

I have an animation defined for a LineSeries

LineSeries values = new LineSeries();

values.enableAnimation(true);

SeriesAnimation entryAnimation = SeriesAnimation.createGrowVerticalAnimation();

entryAnimation.setDuration(0.3f);

entryAnimation.setYScaleCurve(new EaseOutAnimationCurve());

values.setEntryAnimation(entryAnimation);

It works correctly on first display of the chart.

On a button click, I’m using the same method, including the animation, to redraw the chart with new data.

The graph displays correctly but there’s no animation.

Also, is there something else I need to do to clear the graph?


#2

Ok I fixed this issue, in that the LineSeries was being redrawn but the existing one was still being displayed, so you wouldn’t see it. 

I added the following and the graph is correctly cleared and recreated

mPointsAdapter.removeAll(mPoints)

However, I still have an issus on orientation change. The graph fragment is retained, so the original LineSeries is still displayed, then another Line Series is redrawn over the top.

How do I disable the retain? I want to redraw my graph from scratch.


#3

Hello Gary

If you are using a ChartFragment, upon the re-creation of your Activity (as occurs during an orientation change) your ShinobiChart will be recreated with the same state as it had at the point at which it was destroyed. This means of course the series will not perform an entry animation, as it is already shown as it is recreated. If you wish to have the series perform an entry animation each time the Activity is recreated, you will need to handle this yourself. The ChartFragment class does not offer the option to disable state re-creation.

There are several ways in which you could do this depending upon your needs. A simple approach would be to remove your Series in the onDestroy method of your Activity. Similarly, in your Activities’ onCreate method, you would need to ensure that the Series is added to your chart. 

I hope this helps, please let us know if you have any more questions.

Thanks, 

Kai. 


#4

Thanks for your reply. Fortunately, I didn’t need to handle orientation change in the end!

However, I am confused about how to clear the LineSeries. In my case, it redraws correcly if I call removeAll() from the corresponding SimpleDataAdapter.

I think a sample app illustrating the best way to clear and recreat the ChartFragment on orientation change would be very useful.


#5

Hi Gary.

I am glad that your immediate issue is resolved.

I appreciate your feedback regarding a sample app. We do not currently have such an app but you are the first I have encountered with this specific use case. I will make a note of your request and we may consider publishing a blog or similar in the future. I cannot of course guarantee when this may be. 

If you were to approach this task however, I still feel that my previous suggested approach would suit, that is by overriding the onDestroy method, and adding additional code to your onCreate method (of your Activity).

In terms of how you actually ‘reset’ your series, you do have several choices. If you are not concerned with animations, you can simply use the removeAll method on the DataAdapter to ‘reset’ the series, then add the data points within the onCreate method. 

If, on the other hand you wish the Series perform an entry animation each time it is recreated, you will need to either remove and add the Series as I mentioned, or alternatively, hide and show the Series. 

For Series hiding, you would use the following method:

https://www.shinobicontrols.com/docs/ShinobiControls/ShinobiChartsAndroid/1.9.0/Standard/Normal/apidocs/reference/com/shinobicontrols/charts/Series.html#setHidden(boolean)

I hope that this helps. 

Thanks,

Kai.