Stretching out category axis labels

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
dbasten
Posts: 52
Joined: Fri Jul 25, 2003 4:29 pm

Stretching out category axis labels

Post by dbasten » Tue Jun 21, 2005 10:52 pm

I'm stumped on how I can stretch out the display of category axis labels. I'm using JFreeChart 1.0.0 RC1.

Here's the chart:
Image

Here's the snippet of code where I manipulate my category axis:

Code: Select all

		CategoryAxis categoryAxis = new CategoryAxis( y1Label );
		categoryAxis.setMaximumCategoryLabelLines( 1 );

		CategoryLabelPositions positions = new CategoryLabelPositions( new CategoryLabelPosition(
				RectangleAnchor.BOTTOM, TextBlockAnchor.BOTTOM_CENTER ), // TOP
				new CategoryLabelPosition( RectangleAnchor.TOP, TextBlockAnchor.TOP_CENTER ), // BOTTOM
				new CategoryLabelPosition( RectangleAnchor.LEFT, TextBlockAnchor.CENTER_LEFT,
						CategoryLabelWidthType.RANGE, 0.4f ), // LEFT
				new CategoryLabelPosition( RectangleAnchor.LEFT, TextBlockAnchor.CENTER_LEFT ) // RIGHT
		);


		categoryAxis.setCategoryLabelPositions( positions );
		categoryAxis.setLabelInsets( new RectangleInsets( 3, 3, 3, 3 ) );
My goal is to define a maximum width for the category labels, which seems to be accomplished in the code above. However, I also want the axis label ("Hostname") to start on the left margin and have the category axis labels be left justified against that label and displaying as many characters as possible before reaching the display area of the chart.

The behavior I think I see is that the area reserved for axis labels is not what is actually used by the Text Blocks when writing out the labels. Most of the labels are getting cut off prematurely and could display much more (even considering the type of BreakIterator used) if the full space was utilized.

I've tried many different ways of generating the plot (not using the CategoryLabelPositions, changing the insets, etc.), but have had no success.

So... am I just missing something in my configuration of the CategoryAxis that is preventing me from getting the axis labels to display the way I want?

I appreciate any help and tips -- this has been a problem vexing me for some time.

Regards,
David

iceox
Posts: 5
Joined: Fri Apr 08, 2005 4:30 pm

Post by iceox » Wed Jun 22, 2005 1:03 pm

David,

I wonder if you have a way to change the font size of category axis labels? eg. change the font size of "magr...", "labrt", ..., "goodrouter".

I am currently facing that problem, could you help?
Thanks
ice

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Thu Jun 23, 2005 6:31 am

This is a bug, which has been fixed in CVS:

http://cvs.sourceforge.net/viewcvs.py/j ... ABLE_1-0-0
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

dbasten
Posts: 52
Joined: Fri Jul 25, 2003 4:29 pm

Post by dbasten » Thu Jun 23, 2005 3:40 pm

That did the trick!

Thanks David!


Regards,
David

ygehani

Modifying Label width

Post by ygehani » Fri Jul 22, 2005 6:10 am

What did u do?Can u please exaplain?

fclever

use setMaximumCategoryLabelWidthRatio

Post by fclever » Sun Jul 24, 2005 8:27 am

I used the following:
chart.getCategoryPlot().getDomainAxis().setMaximumCategoryLabelWidthRatio(1);

Enjoy,
Flori

CleverSoft GmbH
http://www.clever-soft.com/

Locked