Streaming live data but still allow panning to past data


#1

Hi

I am using a ShinobiChart to plot live time series data, using the approach outlined in the official example, i.e. calling appendNumberOfDataPoints when the new data arrives, followed by a call to chart.redraw().

This works fine, and by default it also tracks the live data, because the axis range is presumably adapted to the data range.

However, my chart can also display quite a large amount of data that is in the past, which the user can reach by panning the chart. Unfortunately the chart jumps back to the recent data when new live data arrives.

So I guess I need some kind of “ignore live update when user is panning the chart and looking at past data” but I haven’t found out yet how to do it. There is a callback in the SChartDelegate for axis range alterations, but it’s invoked not only for user-initiated changes but also when data loads, or is updated.

Is there a way to achieve what I want easily with Shinobi?

Thanks in advance.
Alex


#2

I figured it out: when new data arrives, i compare the displayed range with the data range of the x axis. If the displayed range extends to end of the data range, or beyond, the user is at the rightmost edge of the graph, and live data is added / the graph redrawn.

let xDataRange = self.xAxis.dataRange as! SChartDateRange let xDisplayedRange = self.xAxis.range as! SChartDateRange let isDisplayingLiveData = xDisplayedRange.maximumAsDate() >= xDataRange.maximumAsDate() chartDatasource.appendValue(value: Double(value), at: time) chart.append(numberOfDataPoints: 1, toEndOfSeriesAtIndex: 0) if isDisplayingLiveData { chart.reloadData() chart.redraw() }

Hope this helps somebody else.

cheers
Alex


#3

Hi Alex,

Thanks for posting the solution and we are glad you have managed to overcome your problem. I would recommend checking out our user guide, with specific reference to ranges:

https://www.shinobicontrols.com/docs/ios/shinobicharts/latest/shinobi-userguide.html#The%20Axes

You may find that choosing to preserve the axis range as the data is loading proves useful.

Thanks,

Kai.