Search code examples
iosobjective-cios10pie-chartiphone-6

Missing slices of piechat in iPhone6 works fine for iphone5


I am using BNPieChart. Slices of Piechart in iPhone6s (iOS 10.2.1) gone missing but same code works fine for iPhone5s (iOS 10.2.1) and iPhone5s (iOS 10.2.1).

Here is my code:

- (void)viewDidAppear:(BOOL)animated {

    CGRect pieFrame = CGRectMake(30, 78, 240, 240);
    self.chart = [[BNPieChart alloc] initWithFrame:pieFrame];

    BNColor *emergencyColor = [BNColor colorWithRed:142.0/255.0 green:1.0/255.0 blue:32.0/255.0];
    BNColor *urgentColor = [BNColor colorWithRed:231.0/255.0 green:133.0/255.0 blue:8.0/255.0];
    BNColor *nonUrgentColor = [BNColor colorWithRed:97.0/255.0 green:147.0/255.0 blue:3.0/255.0];

    self.chart.colors = [NSArray arrayWithObjects:emergencyColor,urgentColor,nonUrgentColor, nil];

    [self.chart addSlicePortion:emergencyCount/totalCount withName:[NSString stringWithFormat:@"%.1f%%",(emergencyCount/totalCount)*100]];
    [self.chart addSlicePortion:urgentCount/totalCount withName:[NSString stringWithFormat:@"%.1f%%",(urgentCount/totalCount)*100]];
    [self.chart addSlicePortion:nonUrgentCount/totalCount withName:[NSString stringWithFormat:@"%.1f%%",(nonUrgentCount/totalCount)*100]];

    [self.view addSubview:self.chart];
}

On iphone6 its only display gradient dark gray circle, Have look in image: enter image description here

But it works fine for iPhone5(iOS 10.2.1)

enter image description here


Solution

  • Actually, it needs to be changed in BNPieChart classes itself. There was incompatibility between CGFloat and float* Replace the following lines of code in BNPieChart.m wherever they are written:

    //  CGFloat red, green, blue;
    //  [self getRGBForIndex:index red:&red green:&green blue:&blue];
    

    To

    CGFloat red, green, blue;
    BNColor *color = [colors objectAtIndex:(index % [colors count])];
    red = color.red;
    green = color.green;
    blue = color.blue;
    

    Watch viewDidAppear to achieve the result. It works fine if anybody has implemented BNPieChartlike I did.