Ability to drag data points?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
IanMayo
Posts: 9
Joined: Mon Oct 31, 2005 10:15 am
Location: UK

Ability to drag data points?

Post by IanMayo » Tue Mar 10, 2009 3:22 pm

Hi all,
I've a use-case where I'd like users to be able to drag data-points in a scatter diagram - so changing the data value in the underlying dataset.

This doesn't appear possible from the demonstrator or the forum contents?

Am I missing something?

If the capability isn't in JFreeChart I'm willing to have a go at implementing it, but would value a couple of pointers towards a valid strategy.

cheers,
Ian

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Ability to drag data points?

Post by paradoxoff » Tue Mar 10, 2009 9:59 pm

If you are catching a chartMouseClicked event, you should be able to get a reference to the chart, plot and via the XYItemEntity also to the XYDataset, the series index and the item index.
You could then store that and, in a chartMouseMoved event, record the movement, get the difference in Java2D space, and translate that to a difference in data space with the help of the axes.
However, the XYDataset interface doesn´t give you a way to change/update the data. The XYDataset interface declares only methods for getting the data out.
You can do two things
a) check whether the XYDataset is an instance of DefaultXYDataset, XYSeriesCollection, TimeSeriesCollection... and if you have found the exact class of the dataset, you can cast your dataset object and apply the methods specified in the concrete implementation. Drawback: you will have to test for all implementations until you find the right one. If you are in control about the chosen implementation, i.e. if you already know the class of the XYDataset, you can of course shorten that "trial and error" selection process.
b) For a more general approach: you could declare an interface MutableXYDataset with method setXValue(int series,int item,Number value) and setXValue(int series,int item,Number value) and create derivatives of the existing dataset that implement these interfaces in a suitable way. Then you would only have to check wether the dataset is an instanceof MutableXYDataset and you would have more freedom in selecting a dataset.

Locked