Best practices for reusing charts


#1

I have a dynamic UI with a varying number of charts. The number of charts and what they’re displaying can change at runtime.

Currently I’m using chart fragments but it’s a bit problematic, so planning to move towards just using multiple chart views inside a single fragment or activity. I was wondering, is it worth trying to reuse the charts when I’m changing what they’re displaying or could I just remove the chart views and create fresh ones? I’m talking about typically having 7 charts with 3 line series each…

Thanks


#2

Hello Radu,

Thank you for your enquiry.

The ChartView object is quite a heavyweight View object and so you may find some performance benefit in re-using these objects rather than re-creating them. However, depending upon your application you may find that this approach offers minimal benefit. In this circumstance we would recommend code clarity over perceived performance gain. There is no real right or wrong answer to this question  however and ultimately it will depend upon your application.

I hope that this helps answer your question.

Thanks,

Kai.