I want to have differnt label value for the legends in IGPieChartView. For example : if the label value for Slice1 = "70" then the legend lablel value should be "CLASS A". How can i achieve this in objective-c ?
Hi,
You can customize the legend item text and depending on your requirements you may or may not have to create a custom legend.Pie slices essentially hold value/label pairs and if you know in advance what legend text you want to go with what slice's value you won't need a custom legend. Simply set the labelPath of your datasource helper to your label property (the legend will use this). The slice can then display the value if you handle the following delegate method and return the data point's value:
-(NSString *)pieChartView:(IGPieChartView *)pieChartView label:(NSString *)label item:(IGPieSliceInfo *)item{ IGCategoryPoint *dataPoint = (IGCategoryPoint*)item.item; return [NSString stringWithFormat:@"%.1f", dataPoint.value];}
For more complex cases you will most likely need to create a legend that derives from IGLegend and set the legend item's title property to a string you would like to display.I'm attaching a sample that demonstrates how to handle the custom legend scenario.
It crashes in above method in 2016 volume 1 igframeworks, below is code and crash log:
datapoint is like:
<GList$Object 0x7fc97ab72c30>(<IGPiePoint: 0x7fc97ab65f40>)
and crashes at:
IGCategoryPoint *dataPoint1 = (IGCategoryPoint*)item.item;
dataPoint1.value //here it crashes
Every IGPiePoint derives from IGCategoryPoint, so the cast is valid. Your app crashes because dataPoint1 is nil, which can only happen if item is nil (this is highly unlikely) or item.item is nil. The latter might be due to the presence of the 'Others' slice.Your solution is to check if dataPoint1 is not nil before proceeding further.