kevinzhow / PNChart

A simple and beautiful chart lib used in Piner and CoinsMan for iOS
MIT License
9.71k stars 1.76k forks source link

Pie Chart crash when all PNPieChartDataItem value's are 0 #162

Closed lukegeiger closed 9 years ago

lukegeiger commented 9 years ago

I am getting a crash when I am creating a PNPieChart with 5 PNPieChartDataItems that all have a value of 0, like so.

        NSArray *items = @[[PNPieChartDataItem dataItemWithValue:0 color:[UIColor blueColor]description:@"Desc"],
                       [PNPieChartDataItem dataItemWithValue:0 color:[UIColor greenColor] description:@"Desc"],
                       [PNPieChartDataItem dataItemWithValue:0 color:[UIColor redColor] description:@"Desc"],
                       [PNPieChartDataItem dataItemWithValue:0 color:[UIColor tealColor] description:@"Desc"],
                       [PNPieChartDataItem dataItemWithValue:0 color:[UIColor orangeColor] description:@"Desc"],
                       ];

        self.chart = [[PNPieChart alloc] initWithFrame:CGRectMake((frame.size.width-width)/2, 10, width, width) items:items];

I crash here

With the error:

 *** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position     contains NaN: [nan nan]'
*** First throw call stack:
kevinzhow commented 9 years ago

don't set it all zero @ZhangHang any suggestion?

lukegeiger commented 9 years ago

@kevinzhow I am using the library to display stats on a sports team, so for example at the start of a season all players stats are 0... I am assuming thats a common use case... I came up with a workaround, on my own, but just thought I would bring it to your attention. Cool library!

ZhangHang commented 9 years ago

As for this kind of case , it should dividing equally. I will sent a PR if you guys agree.

kevinzhow commented 9 years ago

@ZhangHang yes, come on!