Ramya
Ramya

Reputation: 1

Interactive bar chart.user changes y axis value at runtime by dragging it

For example 3 columns are there with y axis value as 100,200,300 in barcharts. User select one column alone and drag it to 500 value in y-axis. How to achieve this? Is it available in library like androidplot or aChartPlugin? If not which plugin support this requirement.Our project is for Android tablets Please provide me sample code for this requirement.Thanks in advance.

Upvotes: 0

Views: 367

Answers (1)

Nick
Nick

Reputation: 8317

To my knowledge no library exists for Android that provides 'out of the box' capabilities to drag and reorganize data. Having said that, any library that provides you with a way to correlate touch events to data elements and also supports dynamic updates should be suitable.

If you have specific requirements about how the "drag" is implemented then you may end up having to roll your own library or customize an existing one to your needs. If not, here's a basic workflow you could implement with Androidplot that represents the drag operation as a cursor:

1 - Detect selections using an OnTouchListener. Here's an example of a bar plot that allows bar selection via touch. Gives a full example of converting screen coords to model elements etc. Create and add an instance of XValueMarker denoting the current position of the selection. (An XValueMarker is basically a customizable vertical line marking an x-val.

2 - Detect "drag" events using an OnTouchListener. Here's an example that detects zooming and scrolling. It's not the same thing exactly but the scrolling logic is close enough to give you the general idea.

3 - As the user drags, update the position of the XValueMarker by XValueMarker.setValue(Number).

4 - Once the "drag" ends, remove the XValueMarker and modify the underlying XYSeries to reflect the change using basic data structure manipulation(s).

And of course remember to always call plot.redraw() after each operation that is expected to alter the appearance of the plot in some way.

Upvotes: 1

Related Questions