Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 not 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?

like image 593
Anders Brenna Avatar asked Nov 18 '10 13:11

Anders Brenna


3 Answers

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.

like image 197
Eric Skroch Avatar answered Nov 20 '22 06:11

Eric Skroch


Also, don't forget to set the CPScatterPlot's delegate to point to your object, or it won't get called.

like image 38
Jack Avatar answered Nov 20 '22 05:11

Jack


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.

like image 1
Mark Dalrymple Avatar answered Nov 20 '22 05:11

Mark Dalrymple