changing font colour of title& axis

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

changing font colour of title& axis

Post by atom » Mon Jul 01, 2002 10:37 pm

Hi

I would like to know how can one change the font colour of the title, legend axis and so on.


Thanxs
A.M

David Gilbert

Re: changing font colour of title& axis

Post by David Gilbert » Tue Jul 02, 2002 5:52 am

For axes, there are two methods in the Axis class:

setLabelFont(...);
setTickLabelFont(...);

You need to do something like this (example assumes a CategoryPlot):

CategoryPlot plot = myChart.getCategoryPlot();
ValueAxis axis = plot.getRangeAxis();
axis.setLabelFont(font1);
axis.setTickLabelFont(font2);

For chart titles, there is a setFont(...) method, but the trick is getting hold of the TextTitle object. The chart maintains a list of titles (you can add as many as you want). Use these methods in the JFreeChart class:

getTitleCount();
getTitle(int);
getTitles;

When you access a particular title, it will be returned as an AbstractTitle...you need to cast it to the correct subclass:

AbstractTitle t1 = myChart.getTitle(0);
if (t1 instanceof TextTitle) {
TextTitle t = (TextTitle)t1;
t.setFont(myFont);
}

Regards,

DG.

David Gilbert

Re: changing font colour of title& axis

Post by David Gilbert » Tue Jul 02, 2002 1:21 pm

Sorry, I didn't read that very closely...to change the color use:

setPaint(...) in the TextTitle class;
setLabelPaint(...) in the axis class;

Regards,

DG.

Locked