Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw line graph in Objective C with large number of data and show them in collection view

I have large volumes of data (items/row) stored in a file with extension .rec (just like .text) I need to show the vertices in a line graph supporting pinch zoom and dragging. I can draw the line graph with CoreGraphics. But it doesn't work well with large volumes of vertices. For large volume data it takes more than 3 mins to draw the graph. I need to draw at least 80,000 items (vertices) promptly. My current solution can handle 500 items smoothly. I have no idea how can I handle large volume of items.

I am also showing the items(Only data like row vs column, not graph) in a UICollectionView. Loading time of UICollectionView blocks the main thread and app become fridge. Can you please give me some suggestion how can I support to load large volume data.

You can find the full code, and data file on Github, I need help both on drawing the line graph and UICollectionView.

8000 Data plotted, took 1.5 mins Data on tabular form with collection view

like image 699
kallol Avatar asked Dec 11 '25 23:12

kallol


1 Answers

Don't, the screen resolution isn't high enough to make that volume of points useful anyway. Normalise your data such that you have multiple different zoom levels, like you would when tiling a map. So when zoomed out you see the overall flow, but not specific detail. As you zoom in you use 'more' data points, but in a reduced range, so overall the complexity of the graph remains the same at all levels.

The collection view is a completely different thing. Re-rendering each graph every time the collection scrolls is not going to work well. You'll need to do some caching, either of the graphs or snapshot images of the graphs. You'll need to be careful of memory usage and it'll be very difficult not to have some lag while scrolling to new graphs of you don't prepare them (or snapshots of them) in advance. You should also have paging turned on so you don't have multiple graphs on screen at the same time.

like image 59
Wain Avatar answered Dec 13 '25 15:12

Wain