Touching a plotSymbol in CorePlot
I'm trying to run some code when the user clicks (or touches) a plotSymbol on mye graph created with Core Plot.
This does n开发者_如何学Pythonot work with scatterPlot:
-(void)scatterPlot:(CPScatterPlot *)plot plotSymbolWasSelectedAtRecordIndex: (NSUInteger)index
{
NSLog(@"plotSymbolWasSelectedAtRecordIndex %d", index);
}
But this works well when I use the barPlot:
-(void)barPlot:(CPBarPlot *)plot barWasSelectedAtRecordIndex:(NSUInteger)index
{
NSLog(@"barWasSelectedAtRecordIndex %d", index);
}
What's missing from my attempt to capture when the user clicks or touches on my scatterPlot?
You need to set the plotSymbolMarginForHitDetection
on your scatter plot. You should set it to match the size of your plot symbols or slightly larger if you need a bigger target to click.
Also, don't forget to set the CPScatterPlot's delegate to point to your object, or it won't get called.
If you're setting up your stuff at init time in a subclass of CPTGraphHostingView (say in initWithCoder coming from a xib), your hostedGraph property might get clobbered by Core Plot (at least as of 1.3), and so the tap handling will short-circuit.
https://code.google.com/p/core-plot/issues/detail?id=555
Needless to say this happened to me :-) My workaround is to set the hostedGraph in my numberOfRecordsForPlot if it's not set already.
精彩评论