samedi 25 avril 2015

Add missing years and corresponding values into an array


I've been messing around with the JBChartView library and it seems really good for charting. It's easy enough to use but i'm having some problems getting my data in a format that i need for a particular chart.

The user can enter a value and corresponding year. This is saved using core data. The data could look like as follows:

Year: 0 Value: 100 Year:2 Value 200 Year 3 Value 150

I would create 2 arrays, 1 for the year number and another for the value. in this case though, I would get 3 bars. What i'd like is a bar with value 0 for Year 1.

I think the best way to approach this would be to look through the Year array, check to see if the first value is 0, then check if every consecutive year value is +1. If not, add 1 to the previous year and insert a value of 0 into the values array at the same index position.

I would like to know if this is the best approach and if I could get some help doing the comparison.

Thanks


Aucun commentaire:

Enregistrer un commentaire