I was in the middle of writing a lengthy post asking how to go about writing an updating, scrolling chart like a ticker. It was eaten by the forum, since I apparently was logged out somewhere in between?! Anyway, during the last hour or so I asked all the important questions and went back and forth and finally figured it (almost) out . I won’t let it go to waste and share my findings here and use the opportunity to ask some questions.
First of all, you need a data source that handles all the updating of the chart data (i.e. from an external source, like a stock ticker, or some other measurement). You will have to implement some way to continually retrieve date and when that is done, trigger the chart update. I’ll leave these details out, since everyone wants to do something different here.
Configure your chart like you want. The biggest trouble I had to get this running was to realize, that there seems to be a difference between an axis that is initialized with a fixed and one that is not but gets a range set later on. The former will not reset the axis range after a reloadData: call, while the latter annoyingly does. There doesn’t seem to be a way to make an axis (that wasn’t already initialized with a range) sit still and just change its range like you want it to. It would always go ahead and calculate its range to fit all the data inside. Q: What am I missing here?
When your data updated, you can use reloadData: to let ShinobiChart know about it, and then set the new range that will scroll the new data into view.
[chart reloadData]; [self.chart.xAxis setRangeWithMinimum:fiveMinEarlier andMaximum:lastDate withAnimation:YES];
Like this. I have found that the animation gets choppy or downright skipped when you call reloadData: like this, at essentially the same time as starting the animation. It’s a bit better when you offload the reloading into another thread using dispatch_async(); but still nowhere near smooth as butter. Without reloading the data, everything is smooth, but pointless Q: Why is that? Does reloadData somehow block the main thread? Is it the OpenGL rendering? If so, how could I smoothly scroll the chart while allowing for reloading (some of its) data?
Maybe related Q: What does axisPanningChanged: do?
Thanks, hopefully, this will help somebody and hopefully I can have some answers as well