3
votes

I am drawing a pie chart using the CPTXYGraph in Core Plot. I have used the delegate method

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

to perform some actions when a particular slice of a pie is clicked. But when I touch the piechart I need to have a feedback or some type of image change to be shown to signify that particular slice is touched just like the button events.

Are there any delegate methods to achieve the same.

2
What kind of feedback do you want to provide? Change the fill of the selected slice? Explode the selected slice? Add a label or annotation? Core Plot can do all of those things, but there is no single "selected" indication. - Eric Skroch
I want to just give a button type feedback to every slice. To tell the user that which slice he selected. - Rahul Kalidindi
What do you mean by "button type feedback"? - Eric Skroch
I mean to say that when we touch a button, it changes the color by which the user can tell that the action is registered on the button. I am looking for something similar to that. Or else any type of change in the slice by which user can tell that particular slice of the pie is selected. - Rahul Kalidindi

2 Answers

2
votes

There'll be some work to do.

First of all, Implement this into Pie chart delegate function.

-(void)pieChart:(CPTPieChart *)plot sliceWasSelectedAtRecordIndex:(NSUInteger)index
{
    indexOfPieGraphPlot = index; //gives index of pie which is selected.
    isPieGraphPlot = YES;     //boolean. if set to yes, will call rootcontroller function which will add pop up.
}

Then add the CPTPlotSpaceDelegate in .h file

then use this function

- (BOOL)plotSpace:(CPTPlotSpace *)space shouldHandlePointingDeviceUpEvent:(id)event atPoint:(CGPoint)point
{
    if(isPieGraphPlot) //if yes call showpopup of rootcontroller
    {
    isPieGraphPlot = NO;
    [rootController showPopUpView:point indexForPlot:indexOfPieGraphPlot];
    // point gives the x,y of the pie over which you want a pop up.
    }
    else    // if no then call remove popup from rootcontroller. this, incase user clicks anywhere else in graph.
    {
        [rootController removePopUp];
    }
    return  YES;
}
0
votes

Implement the -sliceFillForPieChart:recordIndex: method in your datasource. Keep track of the selected slice (if any) and use that to decide what fill to apply to each slice. Call -reloadData on the plot any time the selection changes to force it to load new slice fills.