我正在使用 Core Plot 中的 CPTXYGraph 绘制饼图。我使用了委托方法
-(void)pieChart:(CPTPieChart *)plot sliceWasSelectedAtRecordIndex:(NSUInteger)index
单击饼图的特定切片时执行一些操作。但是当我触摸饼图时,我需要显示反馈或某种类型的图像更改,以表明特定切片被触摸,就像按钮事件一样。
是否有任何委托方法来实现相同的目标。
会有一些工作要做。
首先,将此实现为饼图委托函数。
-(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.
}
然后在 .h 文件中添加CPTPlotSpaceDelegate
然后使用这个功能
- (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;
}
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.