I'm not sure if I've found a bug, or whether I'm just going crazy and am suffering from code blindness, but it looks to me as if IntervalMarker is ignoring any font set using setLabelFont().
In brief, my code looks a bit like:
Code: Select all
JFreeChart chart = ...
// ...
IntervalMarker marker = new IntervalMarker(min, max);
String label = "blah";
marker.setLabel(label);
marker.setLabelAnchor(RectangleAnchor.BOTTOM);
marker.setLabelTextAnchor(TextAnchor.BOTTOM_CENTER);
marker.setOutlineStroke(null);
marker.setPaint(new Color(222, 222, 255, 128));
Font labelFont = new Font("Serif", Font.PLAIN, 8);
marker.setLabelFont(labelFont);
chart.getXYPlot().addDomainMarker(marker, Layer.BACKGROUND);
I've tried ferreting down into the source code, and it looks like TextUtilities.drawAlignedString() computes a pair of (x,y) adjustments for the text position based upon the size of the font, using deriveTextBoundsAnchorOffsets(), and this changes with the font size, so that looks to be working.
Having done that, it calls g2.drawString(String, float, float). Now, g2 knows about the font, because it is set on it in AbstractXYItemRenderer.drawDomainMarker() around line 1203, so g2.drawString() should/could know about the font and Do The Right Thing.
Is there anything I've missed that might be causing the text not to be rendered in the specified font?
Cheers!
kgi