Hi,
I am trying to turn my subcategory Label Positions. I know there is a method for the category itself, but not for subcategory. I could not find any method for that. My sub Category labels are pretty long, therefore I need to turn them about 45 degree, so they can be readable.
I am trying to use StackedBarChartDemo3 as an example for creating grouped stacked bar chart.
Does anybody know how to do that?
cheers,
Brian
Label Positisions for sub Category
Hi Brian,
Been mucking about myself this arvo trying to do just that and was about to post the same question!
I dont think its possible using the SubCategoryAxis class. Looking in the drawSubCategoryLabels method I see:
Where the 0.0 is the angle. I guess you could try overriding the method and using a different angle but I suspect that might not play nice with all the other code for reserving space for it?
Im still hopeful theres an easier way to do it. Surely its a common requirement and Im just overlooking something obvious?
(I was going to post a chart img here demonstrating the issue, but apparently as a new user Im not worthy to post images. Wasted 10 minutes getting it ready too, and preview never objected. Grrrrrrr)
Been mucking about myself this arvo trying to do just that and was about to post the same question!
I dont think its possible using the SubCategoryAxis class. Looking in the drawSubCategoryLabels method I see:
Code: Select all
TextUtilities.drawRotatedString(label, g2, xx, yy,
TextAnchor.CENTER, 0.0, TextAnchor.CENTER);
Im still hopeful theres an easier way to do it. Surely its a common requirement and Im just overlooking something obvious?
(I was going to post a chart img here demonstrating the issue, but apparently as a new user Im not worthy to post images. Wasted 10 minutes getting it ready too, and preview never objected. Grrrrrrr)
It seems your question was answered by rohi in the other thread ("Group Stack Bar Chart"). :-)
you are welcome. to rotate your subcategory labels, you will use something like this:
Code:
domainAxis.setSubLabelFont(domainAxis.getSubLabelFont().deriveFont(0, AffineTransform.getRotateInstance(Math.PI / 2.0)));
you might need to play around with the value abit, maybe set 2.0 to 2.5, etc, until you get the angle you desire..
you will also need to offset your labels so that it does not overlap on your primary category labels:
Code:
domainAxis.setCategoryLabelPositionOffset(80);
// or any double value that works for you. it doesn't have to be 80.
hope i was able to help!
Rohi