如何在核心图饼图中启用对部分的触摸选择? [英] How do you enable touch selection of a section in a Core Plot pie chart?
问题描述
我正在使用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.
}
这篇关于如何在核心图饼图中启用对部分的触摸选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!