BarChart legend and Y-axis size

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
manube
Posts: 5
Joined: Wed Aug 08, 2007 4:24 pm
Location: Nice, France
Contact:

BarChart legend and Y-axis size

Post by manube » Wed Aug 08, 2007 4:38 pm

Hello,
I'm trying to increase the size of the number (0->100) on the Y-axis and the size of colored boxes/shapes in the legend as you can see in this picture: emmanuel.lebel.free.fr/exchange/ftp/3371563802233760414.jpg (sorry but i'm not allowed to post urls)

Here is my code:

Code: Select all

// column keys...
String category = "";

// create the dataset...
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(xx, "Paid out commitment", category);
...
        	
JFreeChart chart = ChartFactory.createBarChart(
	"",      					// chart title
	"",             			// domain axis label
	"% of commited amount",		// range axis label
	dataset,                	// data
	PlotOrientation.VERTICAL, 	// the plot orientation
	true,                    	// include legend
	true,
	false
);

chart.setBackgroundPaint(Color.white);
chart.setBorderVisible(false);

// Legend
Font font = chart.getLegend().getItemFont();
font = new Font(font.getName(),font.getStyle(), 24);
chart.getLegend().setItemFont(font);
	
// get a reference to the plot for further customisation...
CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setNoDataMessage("NO DATA!");

// Chart
CategoryItemRenderer renderer = plot.getRenderer();
renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}%", new DecimalFormat("0.00")));
renderer.setItemLabelsVisible(true);
font = renderer.getBaseItemLabelFont();
font = new Font(font.getName(),font.getStyle(), 20);
renderer.setBaseItemLabelFont(font);
plot.setRenderer(renderer);
plot.setOutlinePaint(null);
plot.setOutlineStroke(null);
plot.setBackgroundPaint(Color.white);

// Range Axis
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setRange(0.0, 100.0);
rangeAxis.setTickUnit(new NumberTickUnit(10, new DecimalFormat("0")));
rangeAxis.setUpperMargin(0.1);
font = rangeAxis.getTickLabelFont();
font = new Font(font.getName(),font.getStyle(), 24);
rangeAxis.setLabelFont(font);

font = rangeAxis.getLabelFont();
font = new Font(font.getName(),font.getStyle(), 18);
rangeAxis.setLabelFont(font);
		
ChartUtilities.saveChartAsJPEG(file, chart, width, height);
Thanks,
Manu
Last edited by manube on Wed Sep 05, 2007 10:18 am, edited 1 time in total.

manube
Posts: 5
Joined: Wed Aug 08, 2007 4:24 pm
Location: Nice, France
Contact:

Post by manube » Wed Sep 05, 2007 9:24 am

Hello,
I come back for a little 'up' because I still haven't found a solution (and I hope there is one) neither by myself nor on the forum.
If somebody has an idea or anything else I will take (concerning the range axis units I've searched for tick unit, tick label and tick #!%$ but unsuccessful and the same concerning the legend).

Thanks in advance,

Manu

manube
Posts: 5
Joined: Wed Aug 08, 2007 4:24 pm
Location: Nice, France
Contact:

Post by manube » Wed Sep 05, 2007 10:02 am

This post is now half-resolved.

I've managed to set the tick font size with this method:

Code: Select all

rangeAxis.setTickLabelFont(font);
It is so evident that I don't know how I managed to not find it earlier but if it can help somebody...

Locked