Changing font of category labels

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Dominique

Changing font of category labels

Post by Dominique » Thu Aug 08, 2002 4:07 pm

Hi ,
Does anybody know how to change the labels in the Verticle Stacked Bar Chart? I want to change Category 1 ..... Category 4 to a different font.I know how to change the series font :
((StandardLegend)chartLegend).setItemFont(new Font("ITALIC", 23,23));
Which works fine. I tried to use the setLabelPaint(); in the CategoryPlot class, but does not seem to work.
I would appreciate any help on this
Regards
Dominique

David Gilbert

Re: Changing font of category labels

Post by David Gilbert » Thu Aug 08, 2002 5:51 pm

The category labels are generated using the toString() method on the objects used to represent the categories in the CategoryDataset. So you need to look at the class you are using to implement the CategoryDataset interface, to see what methods it has to change the categories. If it is DefaultCategoryDataset, then you can use the setCategories(...) method.

Regards,

DG.

David Gilbert

Re: Changing font of category labels

Post by David Gilbert » Thu Aug 08, 2002 11:01 pm

Sorry, I didn't read the question properly.

You need to get a reference to the HorizontalCategoryAxis, then call the setLabelFont(...) method:

CategoryPlot plot = myChart.getCategoryPlot();
CategoryAxis axis = plot.getDomainAxis();
axis.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));

Regards,

DG.

Locked