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.
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.
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.