Custom font bug in LogAxis?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Posts: 1
Joined: Tue Feb 02, 2021 4:55 am
antibot: No, of course not.

Custom font bug in LogAxis?

Post by nick13 » Tue Feb 02, 2021 5:01 am

Hi, There appears to be a bug when using custom fonts in a LogAxis:

Font font = new Font("Palatino", Font.BOLD, 18);
LogAxis axis = new LogAxis("Y Axis");
axis.setNumberFormatOverride(new DecimalFormat("0.000"));

If you comment out that last statement (setNumberFormatOverride), the custom font (Palatino) renders correctly. Also renders correctly if you use a NumberAxis. But as soon as you override the number format, the axis renders with the default font.

Seems to be an issue in all recent versions of JFreeChart.


JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.

Re: Custom font bug in LogAxis?

Post by david.gilbert » Tue Apr 27, 2021 6:30 pm

Looks like a bug and, in fact, someone already reported it before:

I think the fix is to change the LogAxis.createTickLabel() method to start like this:

Code: Select all

    protected AttributedString createTickLabel(double value) {
        if (this.numberFormatOverride != null) {
            String text = this.numberFormatOverride.format(value);
            AttributedString as = new AttributedString(text);
            as.addAttribute(TextAttribute.FONT, getTickLabelFont());
            return as;
        } else {
David Gilbert
JFreeChart Project Leader

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