1

Let's assume that I have one instance of the org.jfree.data.xy.DefaultXYDataset and that I am adding two series to it in this way:

dataset.addSeries(name, values);
dataset.addSeries(name2, values)

How can I move the first or the second series by the X or Y offset value?

Assume that offset is always >= 0. By moving 'right' I mean each (x,y) point transform to (x + offset, y) point.

Moving 'left', 'up' and 'down' by analogy.

Łukasz Rzeszotarski
  • 5,791
  • 6
  • 37
  • 68

1 Answers1

1

DefaultXYDataset is convenient for accessing individual elements of different series, but it doesn't expose the methods needed to manipulate the internal data structures in this way. Instead, implement the XYDataset interface by extending AbstractXYDataset, as shown here, where you can encapsulate the offset plumbing. You may also want to look at SlidingXYDataset, cited here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Could you provide any short snippet to show what do you mean by 'offset plumbing'. I would need a flexible solution to efficiently manipulate with quite large amount of data. – Łukasz Rzeszotarski Aug 26 '13 at 14:24
  • I can only guess at what _you_ mean by _offset_; a common use-case is suggested by the two datasets contrasted [here](http://stackoverflow.com/q/5048852/230513); if you have something else in mind, please edit your question to clarify. – trashgod Aug 26 '13 at 17:54
  • Maybe `setDomainPannable(true)`, for [example](http://stackoverflow.com/a/18421887/230513). – trashgod Aug 27 '13 at 10:40
  • After some tests I recognized that keeping the reference to the value's array (double[][]) and modyfying the values inside (you can do whatever transformation you need) and afterwards calling chart.fireChartChanged() solves the problem. However I am not sure what about efficiency, but if JFreeChart doesn't provide API for transformations it seems be a good way. – Łukasz Rzeszotarski Aug 27 '13 at 13:56
  • As an implementation detail, no copies are made in `addSeries()`. – trashgod Aug 27 '13 at 16:15