Can LineChart Labels be put in the foreground?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
rhobit
Posts: 9
Joined: Wed Apr 02, 2014 8:43 am
antibot: No, of course not.

Can LineChart Labels be put in the foreground?

Post by rhobit » Tue Jul 14, 2015 11:34 am

Hi,

I'm using JFreeChart 1.0.10. I have some Charts with multiple LineCharts. Because the LineCharts are drawn after each other, later LineCharts overlap SeriesItemLabels previously drawn (see attachment). Can I place all labels in the foreground?

My thoughts were:
The plot's render()-method calls the renderer's drawItem(), which calls drawItemLabe(). I could use a custom drawItem()-method, which doesn't call drawItemLabel(), and call drawItem() again, which only calls drawItemLabel() this time... Does that make any sense? Is there a better way?

https://www.flickr.com/photos/133085646 ... res/9bjUsm

chrisrhyno2003
Posts: 30
Joined: Thu Jun 18, 2015 5:42 pm
antibot: No, of course not.

Re: Can LineChart Labels be put in the foreground?

Post by chrisrhyno2003 » Wed Jul 15, 2015 2:10 am

This might not be an appropriate answer, but why don't you add a CustomXYToolTip to your plot ?When you hover over the dataset, the tooltip appears. Without any overlap as such. (I hope that works. My apologies if it doesn't fit).

rhobit
Posts: 9
Joined: Wed Apr 02, 2014 8:43 am
antibot: No, of course not.

Re: Can LineChart Labels be put in the foreground?

Post by rhobit » Wed Jul 15, 2015 4:36 pm

Hi,

thanks, every bit of advice is appreciated. Unfortunately, the charts are exported to PDF too... Hard time using tooltips there. Anybody any ideas how to solve my problem?

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

Re: Can LineChart Labels be put in the foreground?

Post by paradoxoff » Thu Jul 16, 2015 11:59 am

Subclassing LineAndShapeRenderer and drawing the item labels in an additional third pass could work.
Whenever it comes to drawing something on a chart, my first recommendation is to implement the drawing in a custom annotation, in your case an CategoryAnnotation. Yo could write a CategoryAnnotation that receives the index of a CategoryDataset as parameter.
In the draw-method of the annotation, you get a reference to the CategoryPlot. With the help of the dataset index, you can get a reference to the CategoryDataset. You can then query its row and column count and the associated values, and draw whatever you like at the position of the data points. Since a CategoryPlot draws its annotations on top of the data series, labels drawn by this approach won't be covered by item labels.

Locked