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
Can LineChart Labels be put in the foreground?
-
- Posts: 30
- Joined: Thu Jun 18, 2015 5:42 pm
- antibot: No, of course not.
Re: Can LineChart Labels be put in the foreground?
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).
Re: Can LineChart Labels be put in the foreground?
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?
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?
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: Can LineChart Labels be put in the foreground?
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.
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.