Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
175
Different label value for legends in IGPieChartView other than series and items
posted

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 ?

Parents
  • 26458
    Suggested Answer
    Offline posted

    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. 

    PieChartCustomLegend.zip
Reply Children