Search code examples
objective-ccore-plot

How to zoom only a particular slice in pie chart (CorePlot ios) and not the entire piechart


How to zoom only a particular slice in pe chart (CorePlot iOS) and not the entire piechart on user interaction.

I know the following method gives the slice touched:

-(void)pieChart:(CPTPieChart *)plot sliceWasSelectedAtRecordIndex:(NSUInteger)index

but i want to zoom only that slice ?


Solution

  • You can "explode" the selected slice. Implement the -radialOffsetForPieChart:recordIndex: method in your datasource and return a positive offset for the selected slice to make it pop out from the rest of the pie.

    You can use the -sliceFillForPieChart:recordIndex: datasource method to control the fill for each slice. This would allow you to adjust the color and/or transparency to highlight the selected slice.

    If you want to make the selected slice larger than the others, use a second pie chart to display the selected slice. Use the same plot data for both plots. On the first one, use the normal slice fill for all but the selected slice, which could be transparent. Reverse that pattern for the second plot, i.e., all slices transparent except the selected one.