0

I am using ShinobiCharts in my iOS app to plot a line chart. This requires a feature where in the default view will be in Days. When i pinch zoom, i will be getting Weeks data, and more pinch zooming will give me Months data. Same applies for zoom out in reverse order. I am not able to find a way to show this data at different zoom levels. Please help me with this. Im using following delegate method to check zoom level

- (void)sChartIsZooming:(ShinobiChart *)chart withChartMovementInformation:
  (const SChartMovementInformation *)information;

but i dont find any way to check zoom levels.

1 Answers1

0

One way of checking this is to determine the number of days currently displayed within the axis' visible range.

First off you'll need a way to record the current granularity of data on display in the chart:

typedef NS_ENUM(NSUInteger, DataView)
{
    DataViewDaily,
    DataViewWeekly,
    DataViewMonthly,
};

The initial view will be DataViewDaily and is assigned within viewDidLoad to the property currentDataView.

Then within sChartIsZooming:withChartMovementInformation: you could do:

- (void)sChartIsZooming:(ShinobiChart *)chart withChartMovementInformation:(const SChartMovementInformation *)information
{
    // Assuming x is our independent axis
    CGFloat span = [_chart.xAxis.axisRange.span doubleValue];

    static NSUInteger dayInterval = 60 * 60 * 24;

    NSUInteger numberOfDaysDisplayed = span / dayInterval;

    DataView previousDataView = _currentDataView;

    if (numberOfDaysDisplayed <= 7)
    {
        // Show daily data
        _currentDataView = DataViewDaily;
    }
    else if (numberOfDaysDisplayed <= 30)
    {
        // Show weekly data
        _currentDataView = DataViewWeekly;
    }
    else
    {
        // Show monthly data
        _currentDataView = DataViewMonthly;
    }

    // Only reload if the granularity has changed
    if (previousDataView != _currentDataView)
    {
        // Reload and redraw chart to show new data
        [_chart reloadData];
        [_chart redrawChart];
    }
} 

Now within your datasource method sChart:dataPointAtIndex:forSeriesAtIndex: you can return the appropriate data points by switching on the value of _currentDataView.

Note that you may need to also update sChart:numberOfDataPointsForSeriesAtIndex to return the number of points to display at the current view level.

sburnstone
  • 586
  • 3
  • 8