Touching a plotSymbol in CorePlot
Asked Answered
F

3

6

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?

Filberto answered 18/11, 2010 at 13:0 Comment(1)
hi am also trying to integrate this funtionality in my code, but when i add this method its not even getting called when we tap on barplot .please explain me clearly,about implimentation of this method.thx in advance...Emersonemery
R
14

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.

Revengeful answered 19/11, 2010 at 0:37 Comment(2)
Thanks a lot! Also worth noting is that you can set the plotSymbolMarginForHitDetection to your plot width/number of symbols so that its easier to select symbols when there are few of them, and but still possible to select a certain symbol when there are many of them.Overcoat
Man I love just how everything is exposed to us in this framework. Well designed.Cytolysin
I
9

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

Illgotten answered 27/4, 2011 at 17:58 Comment(0)
W
1

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.

Wendellwendi answered 29/7, 2013 at 22:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.