如何在核心图饼图中启用对部分的触摸选择?

编程入门 行业动态 更新时间:2024-10-24 08:22:19
本文介绍了如何在核心图饼图中启用对部分的触摸选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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.

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

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

推荐答案

我已经在iPad应用程序中使用CorePlot 0.2.2实现了饼图选择。 。您使用 (void)pieChart:sliceWasSelectedAtRecordIndex:的猜测是正确的,但也许您忘记了声明以下两件事:

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:

  • 您的控制器是否声明了 CPPieChartDelegate 协议?
  • 您是否告诉饼形图,您的控制器就是它的控制器委托?
  • 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

在(void)viewDidLoad ,在其中设置数据源和饼图的委托:

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. }

更多推荐

如何在核心图饼图中启用对部分的触摸选择?

本文发布于:2023-06-07 22:03:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/568573.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图中   核心   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!