Zoom to range


#1

Hello,

I have this question. I have a big data displayed in candles and line charts (one at a time ofcourse :slight_smile: ).
I have initial range setup to show only the latest X records and the user can scroll back to see the rest. I am trying to show that initial visible area zoomed to fill the screen/canvas. Image you have this numbers : 1000, 1200, 1300, 1, 2, 3. So on load i’m showing up just “1, 2, 3” and the user can go back to “1000, 1200, 1300”. Currently the charts are displaying the “1, 2, 3” as candles (for example), but with the zoom level of the whole chart, so the visible candles are too small. I am trying to zoom in on that initial visible range to fill the screen. Also, the X is date axis and Y is number axis, so i only need to zoom on the Y axis to fill up the screen.
Any ideas would be highly appreciated.

Cheers,
S.


#2

Hi Supudo,

Are you using ShinobiCharts for iOS or Android?

Thanks,

Kai.


#3

Hi Kai,

I am trying to achieve it on both platforms, but any tips on any one would be appreciated.

Cheers,
S.


#4

Hi Supudo,

To show your initial range, try using this method before your initial data load:

http://www.shinobicontrols.com/docs/ShinobiControls/ShinobiChartsAndroid/1.5.1/Premium/Normal/apidocs/docs/reference/com/shinobicontrols/charts/Axis.html#setDefaultRange(com.shinobicontrols.charts.Range<T>)

If you need to set a range after the data has been loaded try using this method:

http://www.shinobicontrols.com/docs/ShinobiControls/ShinobiChartsAndroid/1.5.1/Premium/Normal/apidocs/docs/reference/com/shinobicontrols/charts/Axis.html#requestCurrentDisplayedRange(T, T, boolean, boolean)

Please bear in mind when you ask the chart to show any range, it will only do so if this does not violate any restrictions placed on the axis. For example if a request is made to display a range which is greater than the default range, but this option is set to false then the request will be ignored:

http://www.shinobicontrols.com/docs/ShinobiControls/ShinobiChartsAndroid/1.5.1/Premium/Normal/apidocs/docs/reference/com/shinobicontrols/charts/Axis.html#allowPanningOutOfDefaultRange(boolean)

Please let us know how you get on!

Thanks,

Kai.


#5

Hi Kai,

Thanks for the quick response.
I am doing all this - i have a pretty big data set and initially i’m showing only the last 100 bars. The thing is that it’s showing it in the visual context of all the data - no zoom at all. Check this screenshot - http://cl.ly/image/3l1C0X1R2H2E - it illustrates the “issue”. I am trying to zoom the Y axis (in this case) to fit the visible bars nicely in the visible chart area, so that it’s not just a line at the bottom of the screen.

So far i found this in the docs for the “visibleRange” property:
“Setting the default range to this range should frame your data nicely. Note that this will take baselines, bar/column widths etc into consideration and so is not necessarily the same as dataRange.”
But it doesn’t frame the data.

Cheers,
S.


#6

Hello Supudo,

Thanks for the extra information.

Looking at your screen shot, the reason why the candles are so ‘squashed’ is that (as I think you’ve suggested) the y axis has been drawn with a range which caters for all of the points within the series, including those not currently displayed.

You mention that you initially show the latest x number of records. Have you tried the following: 

Before adding any data points to the (Android) data adapter, scan your data’s last x points and note the high and low y values. Use the method setDefaultRange() to set this range on the y axis. Then load the data. This should set the range of the y axis so that the candles fill much more of the plot area and appear much less ‘squashed’. Bear in mind please my earlier note about range requests on axes not being honoured if such a request violates any rules set on the axis. Also, you should use this method before loading the data adapter, not after. Also please bear in mind that as the user scrolls back in time eventually some candles will not be displayed (as their y values will fall outside of the current range of the y axis) and the user would need to zoom out to see them. 

Another approach may be to load the data in chunks. So initially you would load the last x number of records to the series and the axis would automatically set its range to accommodate this data. As the user scrolls back in time, you would dynamically load more data. You would need to think about performance with this solution. Also, if you cleared the series each time you loaded a new ‘chunk’ of data (rather than just add older data points to the adapter), the axes’ ranges may change which would not necessarily give a good user experience.

Let us know how you get on.

I hope you find this information useful,

Thanks,

Kai.


#7

Hi Kai,

Thanks for the solutions.

I did went with the first option before, but had an issue with the range setup for initial loading, after zooming, etc… but finally it works good now.
I take the last data records and get the low and high values, after which i create a range for them and set it up on the Y axis only and with a little more help of the boolean variables :slight_smile: i managed to setup the initial zoom and every other zoom.

Cheers.
S.