【问题标题】:JFreeChart setTickLabelFont() and setLabelFont() not working with iText PDFJFreeChart setTickLabelFont() 和 setLabelFont() 不适用于 iText PDF
【发布时间】:2014-04-08 18:47:04
【问题描述】:

我正在尝试以这种方式设置图表 x 轴的字体:

CategoryPlot plotCat =  (CategoryPlot) chart.getPlot();
CategoryAxis xAxis = plotCat.getDomainAxis();
Font font = new Font("SanSerif", Font.STRIKETHRU, 3);
//or Font font = new Font(Font.FontFamily.HELVETICA, 3, Font.BOLD);
xAxis.setTickLabelFont(font);
//or xAxis.setLabelFont(font);

这是我一直在阅读的解决方案,但它对我不起作用。我不断收到消息:The method setTickLabelFont(Font) in the type Axis is not applicable for the arguments (Font)The method setLabelFont(Font) in the type Axis is not applicable for the arguments (Font)

是什么原因导致我无法对这些标签应用不同的字体?

这可能是因为我正在导入com.itextpdf.text.Font 而不是java.awt.Font,但是com.itextpdf.text.Font 是设置PDF 中其他元素的字体所必需的。如果这确实是问题的原因,我该如何解决这些差异?

【问题讨论】:

    标签: java fonts import itext jfreechart


    【解决方案1】:

    JFreeChart 需要 java.awt.Font。如果您已经在源文件中导入了 com.itextpdf.text.Font,那么您必须使用完全限定的类名来为 JFreeChart 创建一个字体,例如:

    java.awt.Font font = new java.awt.Font(Font.SERIF, Font.PLAIN, 10);
    

    【讨论】:

    • 完美!我不知道如何仅在一行上导入java.awt.Font。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-30
    • 2013-10-15
    相关资源
    最近更新 更多