PeriodAxis: setTickLabelFont() does nothing!

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Post Reply
mhilpert
Posts: 494
Joined: Wed Apr 02, 2003 1:57 pm
Location: Germany

PeriodAxis: setTickLabelFont() does nothing!

Post by mhilpert » Mon Aug 13, 2012 5:24 pm

I just changed my DateAxis with PeriodAxis to workaround the problem with repeating time labels (avoid multiple plottings of same year, e.g.). I got it working now to use PeriodAxis instead of DateAxis. But now my calls to setTickLabelFont() don't work with PeriodAxis anymore! (Work with DateAxis). How can I change the tick label font of PeriodAxis?

My Test chart:

Code: Select all

    private final JFreeChart testBarChart2() {
        JFreeChart result = null;
        
        result = ChartFactory.createTimeSeriesChart("Bar Chart 2", "X-Title", "Y-Title", getTimeSeriesCollection1(), true, true, false);
        
        //time series chart has a line renderer as default, so change it to a bar renderer:
        final XYPlot xyp = result.getXYPlot();
        final XYBarRenderer r = new XYBarRenderer();
        r.setMargin(0.2); //10 % space between bars
        xyp.setRenderer(r);
        
        //x axis label format:
        final DateAxis da = (DateAxis) xyp.getDomainAxis();
        da.setStandardTickUnits(getTickUnitSource(new Month(), "yyyy", null)); //show x axis dates only in years
        
        //replace axis with PeriodAxis to have only 1 x tick label per year:
        PeriodAxis pa = new PeriodAxis("PeriodAxisLabel", new Month(ICUtils.toDate("20040101", "yyyyMMdd")), new Month(ICUtils.toDate("20121231", "yyyyMMdd")));
       // pa.setAutoRangeTimePeriodClass(Year.class);
        PeriodAxisLabelInfo[] info = new PeriodAxisLabelInfo[1];
        info[0] = new PeriodAxisLabelInfo(Year.class, new SimpleDateFormat("yyyy")); //must be Year.class!
        pa.setLabelInfo(info);
        xyp.setDomainAxis(pa);
        
        //axis font:
        pa.setTickLabelFont(new Font("Helvetica", Font.PLAIN, 24)); //no matter what Font (size) I use - always uses same font!
        
        return result;
    }//testBarChart2()
using JFreeChart 1.0.15 with JDK 1.7.0_25

matinh
Posts: 483
Joined: Fri Aug 11, 2006 10:08 am
Location: Austria

Re: PeriodAxis: setTickLabelFont() does nothing!

Post by matinh » Tue Aug 14, 2012 11:46 am

There is a constructor that has an argument "labelFont". I think that's the way to change the font for PeriodAxis.

hth,
- martin

mhilpert
Posts: 494
Joined: Wed Apr 02, 2003 1:57 pm
Location: Germany

Re: PeriodAxis: setTickLabelFont() does nothing!

Post by mhilpert » Wed Aug 15, 2012 8:08 am

So this is no "change" - the API should be extended so that PeriodAxis also supports the change the font after instantiation. => request for enhancement
using JFreeChart 1.0.15 with JDK 1.7.0_25

matinh
Posts: 483
Joined: Fri Aug 11, 2006 10:08 am
Location: Austria

Re: PeriodAxis: setTickLabelFont() does nothing!

Post by matinh » Thu Aug 16, 2012 3:52 pm

Well, it's not the constrcutor of the axis but of the PeriodAxisLabelInfo, which you can set via axis.setLabelInfo().
But I agree with you, that it's not optimal. You could file an enhancement request on the Sourceforge page, or even better: provide a patch.

- martin

Post Reply