How to enable touch section selection in a core plot pie chart?

I use the Core Plot structure to draw a pie chart, and I have no problem drawing the chart itself.

However, I need a pie chart to be interactive in nature, that is, if I click on a particular section in a pie chart, it should trigger navigation on the page with details about that particular section.

I tried to use a method -(void)pieChart:sliceWasSelectedAtRecordIndex:, but this delegate method was never called. What do I need to enable this sensory interaction?

+3
source share
2 answers

iPad- CorePlot 0.2.2. (void) pieChart: sliceWasSelectedAtRecordIndex: , , , :

  • CPPieChartDelegate?
  • , ?

:

@interface YourViewController : UIViewController < CPPieChartDataSource,
                                                   CPPieChartDelegate,
                                                   ... >
{
   ...
   CPXYGraph*          pieGraph;
   CPGraphHostingView* pieView;
}

@property (nonatomic, retain) IBOutlet CPGraphHostingView* pieView;

- (void)pieChart:(CPPieChart *)plot sliceWasSelectedAtRecordIndex:(NSUInteger)index;

@end

(void) viewDidLoad, :

-(void)viewDidLoad {
   [self createPie];
}

-(void)createPie {
   pieGraph = [[CPXYGraph alloc] initWithFrame:CGRectZero];
   pieGraph.axisSet = nil;
   self.pieView.hostedGraph = pieGraph;

   CPPieChart *pieChart = [[CPPieChart alloc] init];

   // This is important in order to have your slice selection handler called!
   pieChart.delegate = self;

   pieChart.dataSource = self;

   pieChart.pieRadius = 80.0;
   [pieGraph addPlot:pieChart];
   [pieChart release];
}

- (void)pieChart:(CPPieChart *)plot sliceWasSelectedAtRecordIndex:(NSUInteger)index {
   // Do whatever you need when the pie slice has been selected.
}
+6

corePlot framework (1.4), CPPieChart, CPTPieChartDelegate:

@interface CPDFirstViewController : UIViewController <CPTPlotDataSource, CPTPieChartDelegate, ...>

:

-(void)pieChart:(CPTPieChart *)pieChart sliceWasSelectedAtRecordIndex:(NSUInteger)index
{
  // Put your action here
}

CPPieChartDelegate Xcode, CorePlot 1.4

, .

0

Source: https://habr.com/ru/post/1781592/


All Articles