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,
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.
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
The legend typically takes care of arranging the legend items for you in a scrollviewer. If you need to do some sort of dynamic resizing or if you need to arrange items in a different container to wrap them you can do so in a custom legend. Check out the sample in this post, where it shows a custom legend using a different container to wrap the items. You should also be able to set the container's size if the items don't all fit.
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.
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.