Get value when user touches graph - Android

(this is just a screenshot from another app)

I'm trying to achieve this using

I want to have a crosshair appear when the user touches the graph and to have show the value of the X axis of that point.


You will need a method to translate X-position on the screen to X-position on the graph, and display the Y value that corresponds with the looked up X position in the graph.

Most simplistic way I can think of would be to get the pixel width of the screen (assuming your graph fits the entire width), and register for touch events by overriding this method below in the view:

public boolean onTouchEvent(MotionEvent event)
 //TODO get x position tapped on the view and translate to x position on graph

Inside that method you can get hold of the x-coordinate tapped (from the MotionEvent object), and then translate to the graph's position.

For example, you may work out what percentage of the way along the screen is tapped (say the screen width is 400px and the user taps 300px along, thats 75% of the length) then move this percentage through the graph's data points (so 75% through the ordered dataset)

You can then display a popup or add something to your onDraw method that adds the data point as a small overlay.

Note: You would need the raw data points to perform the lookup, unless you are going to try and guess what the graph's points correspond to on the y-axis...

Need Your Help

pwrite() on OSX 10.6 not honoring 64-bit offsets

c osx osx-snow-leopard posix

I seem to be having an odd problem with pwrite() on OSX 10.6.8 when attempting to write to an offset beyond 2GB. I keep catching a SIGXFSZ signal, meaning that the file-size limit has been exceeded.

How to use GLKit within the Xcode OS X Swift Playground?

xcode glkit swift swift-playground

I'm trying to use GLKit within the Xcode 6 OS X Swift Playground but the

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.