我有一些使用自定义字体(Dejavu Serif)的JasperReports报表,在开发和生产环境中都可以正常工作。今天我向该报表添加了一些图表,并将所有字体设置配置为Dejavu Serif。图表本身可以正常工作,但我看不到任何标签,所以我认为问题出在自定义字体上。我找到了一个post,但无法理解他们如何解决这个问题。
更新#1: 因此,我实现了Customizer类,该类配置标签的字体:
更新#1: 因此,我实现了Customizer类,该类配置标签的字体:
public class CustomFontCategoryChartCustomizer implements JRChartCustomizer {
/**
*
*/
@Override
public void customize(JFreeChart chart, JRChart jasperChart) {
CategoryPlot plot = chart.getCategoryPlot();
Font customFont = new Font("DejaVu Serif", Font.BOLD, 12);
// Works fine
plot.getDomainAxis().setTickLabelFont(customFont);
plot.getRangeAxis().setTickLabelFont(customFont);
plot.getRangeAxis().setUpperMargin(0.5);
// Doesn't work
LegendItemCollection legends = plot.getLegendItems();
for (int i = 0; i < legends.getItemCount(); i++) {
legends.get(i).setLabelFont(customFont);
}
plot.getLegendItems().addAll(legends);
// Doesn't work
LegendItemCollection legends = plot.getLegendItems();
for (int i = 0; i < legends.getItemCount(); i++) {
plot.getLegendItems().get(i).setLabelFont(customFont);
}
}
}
除了图例标签之外,一切都很好。无法使用自定义字体使其正常工作。需要帮助吗?