piaoyongren / core-plot

Automatically exported from code.google.com/p/core-plot
0 stars 0 forks source link

Touch- Event in the BarChart or Pie-Chart? #168

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi Core-Plot Team,

I'm searching and searching, but i can't find a solution to interact on 
touching a single Bar created in a BarChart. For Example, i want to do 
something by clicking the 3rd Bar of 5 and save the Length of the Bar. I tried 
to realise this by the touchesBegan method, but i can't identify which Bar is 
touched.

Thank you for help!

Jonathan

Original issue reported on code.google.com by Hummer10...@gmail.com on 6 Jul 2010 at 12:49

GoogleCodeExporter commented 8 years ago
You may have to do this in a round about way. You can become the delegate of 
the CPXYPlotSpace, and that way you can receive the touch events. In the 
delegate method, use the point conversion methods of the plot space to 
determine the x coordinate of the touch in the plot coordinate space. Compare 
this value with the plot coordinate values of your bars to figure out which one 
has been hit, or is nearest.

Original comment by drewmcco...@mac.com on 6 Jul 2010 at 2:07

GoogleCodeExporter commented 8 years ago
Hello, I too have been attempting to find my way on exactly this issue for 
quite some time. It seems there are many in the same boat. Does anyone know of 
any actual examples matching a touch event to a bar/line/plot?

Original comment by gareth.c...@gmail.com on 11 Jul 2010 at 5:09

GoogleCodeExporter commented 8 years ago
I tried the to realize the suggestion of drewmcco.. but i had a lot of problems 
to complete this.
I would also be very pleased if someone implement this in an example, because 
in the further process, i need this function.

Thank you,

Jonathan

Original comment by Hummer10...@gmail.com on 11 Jul 2010 at 6:17

GoogleCodeExporter commented 8 years ago
I don't know of an example, but the following should work:

1) Set the delegate of the CPXYPlotSpace to your controller object
2) Implement this delegate method:

-(BOOL)plotSpace:(CPPlotSpace *)space 
shouldHandlePointingDeviceDownEvent:(id)event atPoint:(CGPoint)point;

3) Return YES from the method, to indicate you handled the touch event. Take 
the point, and use the CPXYPlotSpace method

-(void)plotPoint:(NSDecimal *)plotPoint forPlotAreaViewPoint:(CGPoint)point;

to convert the view point to a plotting coordinates point. 

4) Loop over your data and compare the values to the plot coordinates from 3 to 
determine if any bar is close enough.

Hope that helps.

Drew

Original comment by drewmcco...@mac.com on 12 Jul 2010 at 7:36

GoogleCodeExporter commented 8 years ago
is touch event supported in pie chart.

Original comment by monikadh...@gmail.com on 20 Jul 2010 at 8:04

GoogleCodeExporter commented 8 years ago
Drew, thanks for the suggested workflow, it does work for small datasets, but 
for large ones it is far away from efficient detection and can take 
considerable amount of time especially for realtime line charts. Is there any 
better/more efficient solution?

Original comment by justver...@gmail.com on 24 Jul 2010 at 4:17

GoogleCodeExporter commented 8 years ago
The efficiency of the method is really entirely up to you. I assume the 
expensive step is looping over your data and seeing if any point is close to 
the touched point. 

You can structure/store your data in ways to make this a more efficient 
process, or use inherent structure to improve performance. For example, if your 
data is evenly spaced in x, you should be able to do a simple division of the 
interval to determine the closest point, and then test against that one point. 
This turns an O(n) algorithm (looping) into an O(1) algorithm.

Drew

Original comment by drewmcco...@mac.com on 25 Jul 2010 at 10:54

GoogleCodeExporter commented 8 years ago
JustVersus - I am trying to implement the same thing i:e to be able to detect 
when a specific bar is tapped. IS it possible for you to mail me your code - 
abhishekrohatgi@gmail.com . Thanks in advance

Original comment by abhishek...@gmail.com on 1 Sep 2010 at 3:29

GoogleCodeExporter commented 8 years ago
Touch detection in the plots has been added to the Core Plot framework since 
this issue was opened. Set a delegate for your CPBarPlot and implement 
-barPlot:barWasSelectedAtRecordIndex:. See CPTestApp for an example.

Original comment by eskr...@mac.com on 1 Sep 2010 at 10:38

GoogleCodeExporter commented 8 years ago
Thanks Eric for the quick response it worked. 

Original comment by abhishek...@gmail.com on 1 Sep 2010 at 9:40

GoogleCodeExporter commented 8 years ago
hi,

how to use touch event in pie chart to change the pieRadius dynamicaaly when 
touch the pie chart 

Original comment by agrawala...@gmail.com on 14 Nov 2011 at 6:25