0

I am using shinobicharts ChartFragment. I have scenario that each time I have to load the chart with different data within same activity i.e I am not recreating that activity. But I am failed to do this. It not recreating and not clearing the series which I previously set to that chart.

Can anybody help, how can I remove old series in that chart and load new series each time? I tried shinobiChart().removeSeries() but it didn't work.

Thanks

Abhinav Singh Maurya
  • 3,313
  • 8
  • 33
  • 51
ImGenie
  • 323
  • 1
  • 15

1 Answers1

0

If you wish to dynamically load new data, you do not necessarily need to remove the series. Instead you can simply add data points to your data adapter. You will find the following methods useful: https://www.shinobicontrols.com/docs/ShinobiControls/ShinobiChartsAndroid/1.7.2/Premium/Normal/apidocs/docs/reference/com/shinobicontrols/charts/DataAdapter.html#add(int, com.shinobicontrols.charts.Data) https://www.shinobicontrols.com/docs/ShinobiControls/ShinobiChartsAndroid/1.7.2/Premium/Normal/apidocs/docs/reference/com/shinobicontrols/charts/DataAdapter.html#add(com.shinobicontrols.charts.Data) https://www.shinobicontrols.com/docs/ShinobiControls/ShinobiChartsAndroid/1.7.2/Premium/Normal/apidocs/docs/reference/com/shinobicontrols/charts/DataAdapter.html#addAll(int, java.util.Collection>) https://www.shinobicontrols.com/docs/ShinobiControls/ShinobiChartsAndroid/1.7.2/Premium/Normal/apidocs/docs/reference/com/shinobicontrols/charts/DataAdapter.html#addAll(java.util.Collection>)

In these api docs you will also find similar methods to remove data points.

One thing to bear in mind is that adding or removing a data point to / from a SimpleDataAdapter class instance which is set on a series will trigger a redraw of that series. If you are working with large numbers of data points, this might not be performant. In this case a more suitable approach might be to temporarily remove the data adapter from the series, perform the modification to the data and then re add the data adapter back to the series. Alternatively you might like to implement your own DataAdapter and control when you instruct the chart to redraw that series (via the fireUpdateHandler method).

You can of course remove the series itself and add a new one, but this approach is potentially inefficient. That said, if you wish to remove a series from a chart you need to use the following method:

https://www.shinobicontrols.com/docs/ShinobiControls/ShinobiChartsAndroid/1.7.2/Premium/Normal/apidocs/docs/reference/com/shinobicontrols/charts/ShinobiChart.html#removeSeries(com.shinobicontrols.charts.Series)

In order for this method to be successful you will first need to obtain a reference to the correct series, which you must pass to this method as a parameter.

I hope that you find this information useful. If you need any further help please if possible post any relevant code, such as that which you use to create your fragments and set up your chart. Thanks and kind regards, Kai.

Disclaimer - I work for ShinobiControls.

Kai
  • 186
  • 2
  • 10
  • thanks that helps. As u said I have lots of data showing in bar chart I can't even see that data on Bar series. So for that reason I am showing 10 at a time and reloading with a button click with next 10. Its working fine so far. But as u said I think it seems to be inefficient because I am removing an adding series each time. – ImGenie Nov 05 '15 at 05:42