sChartDidFinishLoadingData infinite loop


#1

Hello,

I’m getting a strange behavior with the SChartDelegate callbacks.  I’m creating the chart axises within sChartDidFinishLoadingData and styling them there (because the range padding is dependent on the data the chart gets), but as soon as I assign these axises to the chart, it triggers sChartDidFinishLoadingData to be called again and again in an infinite loop.  The user guide documentation discusses sChartDidFinishLoadingData and the Lifecycle of a Chart: “At this point, the chart axes will have been refreshed from the new data, so you could update the chart axes here before they are rendered.”

- (void)sChartDidFinishLoadingData:(ShinobiChart *)chart {
    SChartNumberAxis *yAxis = [[SChartNumberAxis alloc] init];
    
    // calculate reasonable padding for ranges
    double maxChartValue = [self maxValueInChart];
    double minChartValue = [self minValueInChart];
    double delta = maxChartValue - minChartValue;
    NSNumber *deltaPadding = [NSNumber numberWithDouble:delta * .10];
    yAxis.rangePaddingHigh = deltaPadding;
    yAxis.rangePaddingLow = deltaPadding;
    
    
    SChartCategoryAxis *xAxis = [[SChartCategoryAxis alloc] init];
    
    // remove the x-Axis line altogether
    SChartAxisStyle *xAxisStyle = xAxis.style;
    xAxisStyle.lineWidth = @0;
    
    SChartTickStyle *xAxisMajorTickStyle = xAxisStyle.majorTickStyle;
    xAxisMajorTickStyle.tickGap = @-40;
    xAxisMajorTickStyle.labelColor = [UIColor blackColor];
    xAxisMajorTickStyle.labelFont = [UIFont fontWithName:@"HelveticaNeue-Bold" size:12.0];
    xAxisMajorTickStyle.textAlignment = NSTextAlignmentLeft;
    
    // if I comment out the below lines, it eliminates the recursion
    chart.yAxis = yAxis;
    chart.xAxis = xAxis;
}

#2

Hi,

I’m afraid currently we reload data when axes are set, which is what’s causing the recursion. Currently this isn’t supported behaviour, however it can easily be worked around by setting the axes on the next runloop, using something like performSelector:afterDelay: to queue up that code to run.

Hope this helps!