Label Positisions for sub Category

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
blajevardi
Posts: 9
Joined: Tue Nov 21, 2006 2:19 am

Label Positisions for sub Category

Post by blajevardi » Thu Nov 30, 2006 6:47 pm

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

ahill
Posts: 7
Joined: Mon Nov 20, 2006 11:22 pm
Location: Singapore

Post by ahill » Mon Dec 04, 2006 9:24 am

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:

Code: Select all

TextUtilities.drawRotatedString(label, g2, xx, yy,
                TextAnchor.CENTER, 0.0, TextAnchor.CENTER);
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)

ahill
Posts: 7
Joined: Mon Nov 20, 2006 11:22 pm
Location: Singapore

Post by ahill » Mon Dec 04, 2006 9:44 am

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

Locked