如何启用 Core Plot 饼图中的某个部分的触摸选择?

发布于 2024-10-08 17:55:27 字数 221 浏览 5 评论 0原文

我正在使用 Core Plot 框架来绘制饼图,并且在绘制饼图本身时没有任何问题。

但是,我需要饼图本质上是交互式的,即,如果我点击饼图中的任何特定部分,它应该触发导航到显示该特定部分的详细信息的页面。

我尝试使用方法 -(void)pieChart:sliceWasSelectedAtRecordIndex:,但该委托方法从未被调用。我需要什么才能启用这种触摸交互?

I am using the Core Plot framework to draw a pie chart, and am having no issues in drawing the pie chart itself.

However, I need the pie chart to be interactive in nature, i.e., if I tap on any particular section in the pie chart, it should trigger the navigation to a page showing details of that particular section.

I tried using the method -(void)pieChart:sliceWasSelectedAtRecordIndex:, but that delegate method was never called. What do I need to enable this touch interaction?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

胡大本事 2024-10-15 17:55:30

使用最后一个corePlot框架(1.4)我找不到CPPieChart,但我用CPTPieChartDelegate修复:

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

和这个方法:

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

CPPieChartDelegate使用 CorePlot 1.4,code> 不再被识别为来自 Xcode 的委托

希望它有帮助。

多姆

Using the last corePlot framework (1.4) i could not find CPPieChart but I fixed with CPTPieChartDelegate:

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

and this method:

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

CPPieChartDelegate is not recognized any more as Delegate from Xcode, using CorePlot 1.4

Hope it helps.

dom

獨角戲 2024-10-15 17:55:29

我已经使用 CorePlot 0.2.2 在我的 iPad 应用程序中实现了饼图选择。你的猜测使用
(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.
}

I have implemented pie piece selection in my iPad app with CorePlot 0.2.2. Your guess to use
(void)pieChart:sliceWasSelectedAtRecordIndex: is correct, but maybe you have forgotten
to declare the following two things:

  • Does your controller declares the CPPieChartDelegate protocol?
  • Did you tell the pie chart that your controller is its delegate?

My view controller looks like this in the header declaration:

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

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

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

@end

The creation of the pie chart is called during the (void)viewDidLoad, where I set the data source and the delegate of the pie chart:

-(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.
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文