Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
5020
Chart yAxis Precision and Scale for Marginal Value Changes
posted

Check out the yAxis on the scale.  Notice how there are 3 points for 136.6 and 3 points for 136.4... but only one point for 136.5.

These kinds of situations tend to correct themselves over time, but it would be nice if they didn't show up.

Here is the yAxis formatter...

-(NSNumberFormatter*)yAxisLabelFormatter

{

    if(!_yAxisLabelFormatter)

    {

        _yAxisLabelFormatter = [[NSNumberFormatter alloc] init];

        _yAxisLabelFormatter.numberStyle = NSNumberFormatterDecimalStyle;

        _yAxisLabelFormatter.groupingSize = 0;

        _yAxisLabelFormatter.maximumFractionDigits = 1;

        _yAxisLabelFormatter.minimumSignificantDigits = 1;

        _yAxisLabelFormatter.minimumFractionDigits = 0;

    }

    

    return _yAxisLabelFormatter;

}

And it's being used as you'd expect...

-(NSString*)chartView:(IGChartView*)chartView

         labelForAxis:(IGAxis*)axis

             withItem:(NSObject*)item

{

    NSString *label = nil;

   

    if ([axis isKindOfClass:[IGNumericYAxis class]])

    {

        label = [self.yAxisLabelFormatter stringFromNumber:((NSNumber*)item)];

    }

.....

Parents
No Data
Reply
  • 21382
    posted

    Hey Caylan,

    There seems to be an oddity in the NSNumberFormatter  which is contributing to the issue

    If you tried the following code snippet out you would see what we are seeing here

    NSNumberFormatter *formatter = [[NSNumberFormatter alloc]init];

    formatter.numberStyle = NSNumberFormatterDecimalStyle;

    formatter.maximumFractionDigits = 1;

    [formatter stringFromNumber:@1.15]        1.2

    [formatter stringFromNumber:@1.20]        1.2

    [formatter stringFromNumber:@1.25]        1.2

    [formatter stringFromNumber:@1.30]        1.3

    [formatter stringFromNumber:@1.35]        1.4

    [formatter stringFromNumber:@1.40]        1.4

    [formatter stringFromNumber:@1.45]        1.4



    As for a fix, well the only thing that I can think of would be to ensure your y range wouldn't do this would be to adjust your min/max on the axis along with the interval to prevent .5 rounding.

Children