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
Hi Max,
Thanks for the quick response. The example was helpful, the problem is solved. I am able to achieve the requirement of having different label value for silce and legend.
I have one more query.
How we can dynamically adjust the size of legend view depending on the number of legendLabel value ? I want to adjust both width and height, so that there will not be ovelaping of legend label.