1

I have a JFreechart, showing stocks data, the type of dataset i use to plot it is an OHLCDataset.

I can get the actual X value from the point where the user click on the plot (i mean, i get the real date corresponding to that point, not just the coordinate on the window).

Next step i need to make is get the data from the OHLCDataset corresponding to that date, to be able to get the Open.High,Close and Low values in that date, but i just can find ways to get the OHLCDataset date corresponding to an item (an integer wich indicates the ordinal), not even one way to obtain that item having the date.

¿Any ideas of how to get the item having the date?

Thanks.

Alberto Martín
  • 439
  • 13
  • 26

1 Answers1

3

The approach suggested is tedious and error-prone. Instead, add a ChartMouseListener, as shown here. You can invoke getDataset() on any XYItemEntity you encounter.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • 1
    Sounds really good. I can't try it now, but i'll do tomorrow. By the moment i must give you 1 vote since if it doesn't solve my problem, its going to be really close to. – Alberto Martín May 08 '12 at 05:29
  • It almost does it... It works if the user click on the candle, but not if clicks in the same vertical, out of the candle. In other words, something that returns the item corresponding to the date clicked (X - axis). Thanks anyway; it was a good idea. – Alberto Martín May 08 '12 at 16:21
  • I'd still use the approach, but with a larger definition of `getArea()` when collecting entities in `mouseClicked()`. – trashgod May 08 '12 at 18:37
  • Thanks again for the advice; the problem is that doing it in that way, there are many scenarios where you are going to get a wrong item :S because the item corresponding to the date where the mouse pointer is may be farther than another item, which would be the one you get; this one easily would be nearest to the point clicked, but it wouldn't correspond to that date. As chart graphs are not a horizontal line, you couldn't do it that way. On the other hand, there may be dates whithout items in it, and you should be able to retrieve that date the mouse is over, whether there is an item in it. – Alberto Martín May 10 '12 at 18:09