BarChartDemo - rotation of x-axis labels

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
luis_esru
Posts: 42
Joined: Tue Jan 20, 2004 6:40 pm
Location: Glasgow
Contact:

BarChartDemo - rotation of x-axis labels

Post by luis_esru » Thu Feb 12, 2004 9:24 am

David

I have the BarChartDemo with 13 categories and 3 series each. Because the categories' labels are too long I'm rotating them to the vertical position in order to avoid overlapping. But the label instead of staying below the center series stays below the right series? Why?

...
CategoryAxis domainAxis = plot.getDomainAxis();
CategoryLabelPosition position = new CategoryLabelPosition(
RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_CENTER, -Math.PI / 2.0
);
domainAxis.setBottomCategoryLabelPosition(position);
domainAxis.setLowerMargin(0.0);
domainAxis.setUpperMargin(0.0);
...

Rgds
Luis
University of Strathclyde in Glasgow
ESRU
luis@esru.strath.ac.uk

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 Feb 12, 2004 11:22 am

The TextBlockAnchor defines which point on the label is aligned to the (x, y) location on the screen. At the moment, you are aligning the TOP_RIGHT of the text to that point - try CENTER_RIGHT and the alignment should be what you are looking for.
David Gilbert
JFreeChart Project Leader

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

luis_esru
Posts: 42
Joined: Tue Jan 20, 2004 6:40 pm
Location: Glasgow
Contact:

Post by luis_esru » Thu Feb 12, 2004 11:32 am

It works!
Rgds
Luis
University of Strathclyde in Glasgow
ESRU
luis@esru.strath.ac.uk

cochese
Posts: 1
Joined: Thu Feb 19, 2004 1:27 pm

Label Wrapping

Post by cochese » Thu Feb 19, 2004 1:30 pm

Hi Guys,

Thanks for the tips - I've had to set my label vertically as well because they are so long. But now they're wrapping and overlapping. Any idea how to disable the text wrapping for the label rectangle, or even a way to increase the Label's rectangles size?

Thanks in advance,

Cochese

phamdinhnguyen
Posts: 22
Joined: Thu Jan 29, 2004 8:28 pm

BarChartDemo - rotation of x-axis labels

Post by phamdinhnguyen » Mon Mar 01, 2004 6:37 pm

Try this:

CategoryPlot oPlot;
CategoryAxis oAxis;
oPlot = oChart.getCategoryPlot();
oAxis = oPlot.getDomainAxis();
oAxis.setCategoryMargin(0.25); // twenty-five percent
oAxis.setLowerMargin(0.04); // four percent
oAxis.setUpperMargin(0.04); // four percent
oAxis.setMaxCategoryLabelWidthRatio(10);

// I played with drawing a single chart with either VERTICAL or HORIZONTAL, and need this only for vertical orientation
if(oChartOrientation == PlotOrientation.VERTICAL)
oAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);

Good luck!
phamdinhnguyen

Locked