0

enter image description here

How would I add tooltips to a TextAnnotation on a JFreeChart barchart?

Specifically, I want to add a tooltip to a CategoryTextAnnotation:

CategoryTextAnnotation a = new CategoryTextAnnotation("long piece of text...", x-coordinate, y-coordinate);

To prevent a long annotation from taking up too much space on the graph, I am limiting the amount of characters that can be shown. However, I want to be able to see the full annotation in a tooltip by hovering over the shortened annotation text. As in the example picture, I want to hover my cursor over "long piece of text..." and have a tooltip show up.

abagshaw
  • 6,162
  • 4
  • 38
  • 76
  • Probably duplicate of https://stackoverflow.com/questions/6797012/jfreechart-series-tool-tip-above-shape-annotation – Akash Jul 24 '17 at 18:02
  • I see support for tooltips in `XYAnnotation`, but not `CategoryAnnotation`. Why not display the long text in a custom `CategoryToolTipGenerator`? Please edit your question to include a [mcve] that shows your current approach. – trashgod Jul 25 '17 at 00:16
  • @trashgod Okay so this might sound weird, but I don't want any data points. I'm just looking to display text itself (the annotations) on a plot. From what I understand, the CategoryToolTipGenerator requires values from a dataset, and I just have a blank dataset. – Emily Wang Jul 25 '17 at 14:02
  • Maybe a `org.jfree.chart.title.Title`? – trashgod Jul 25 '17 at 19:48
  • @trashgod A org.jfree.chart.title.Title as opposed to annotations? It seems like Title only has specific positions it can be in, so I wouldn't be able to plot it. – Emily Wang Jul 26 '17 at 15:16
  • I am unable to resolve this contradiction. – trashgod Jul 26 '17 at 15:43
  • @trashgod lol I meant that for horizontal alignment, Title can only be in the positions LEFT, RIGHT and CENTER, and for vertical alignment, Title can only be in the positions TOP, BOTTOM and CENTER. – Emily Wang Jul 26 '17 at 16:49
  • Used in combination, you'd have a total of nine positions. – trashgod Jul 26 '17 at 19:00
  • @trashgod I need more than 9 positions, and in specific locations that can't be described as LEFT TOP or RIGHT BOTTOM. – Emily Wang Jul 26 '17 at 19:18
  • Cross-posted [here](http://www.jfree.org/forum/viewtopic.php?f=3&t=117852) for reference. – trashgod Jul 26 '17 at 23:26

0 Answers0