Hi,
I currently have the following graph:
What I would like to do is to shift the legends on the domain axis, like that:
I searched around the web, but I couldn't find how to do this. Is it even possible?
Thank you!
BarChart : shift domain axis legend
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: BarChart : shift domain axis legend
Get a reference to your chart, and put these lines in your code:
Code: Select all
CategoryAxis a = chart.getCategoryPlot().getDomainAxis();
CategoryLabelPositions positions = a.getCategoryLabelPositions();
CategoryLabelPosition newBottom = new CategoryLabelPosition(RectangleAnchor.LEFT, TextBlockAnchor.BOTTOM_LEFT);
CategoryLabelPositions newPositions = CategoryLabelPositions.replaceBottomPosition(positions, newBottom);
a.setCategoryLabelPositions(newPositions);
Re: BarChart : shift domain axis legend
Thank you very much for your answer. This gives me the following:
Is there a way to shift them even more to the left, so that they are centered below the vertical lines of the bars?
Is there a way to shift them even more to the left, so that they are centered below the vertical lines of the bars?
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: BarChart : shift domain axis legend
Replace TextBlockAnchor.BOTTOM_LEFT with one of the following and see which one looks best:
TextBlockAnchor.BOTTOM_CENTER, TextBlockAnchor.CENTER,TextBlockAnchor.TOP_CENTER
TextBlockAnchor.BOTTOM_CENTER, TextBlockAnchor.CENTER,TextBlockAnchor.TOP_CENTER
Re: BarChart : shift domain axis legend
TextBlockAnchor.BOTTOM_CENTER looks perfect, thanks!