调整JFreeChart的域轴标签和值轴标签字体大小

14

我的目标是增加"Revenue ($) "和"Years"的数量,但我不知道如何实现。我能够增加"Apples, Durians, Oranges"和"2012, 2013"。

以下是我的代码:

image

    JFreeChart chart = ChartFactory.createBarChart3D("", // chart title
                "Years", // domain axis label
                "Revenue ($)", // range axis label
                dataset, // data
                PlotOrientation.VERTICAL, // orientation
                false, // include legend
                false, // tooltips
                false);

CategoryPlot plot = chart.getCategoryPlot();
        CategoryAxis axis = plot.getDomainAxis();

        CategoryPlot p = chart.getCategoryPlot(); 
         ValueAxis axis2 = p.getRangeAxis();

        Font font = new Font("Dialog", Font.PLAIN, 25);
        axis.setTickLabelFont(font);
        Font font2 = new Font("Dialog", Font.PLAIN, 15);
        axis2.setTickLabelFont(font2);

        LegendTitle legend = new LegendTitle(plot.getRenderer());

        Font font3 = new Font("Dialog", Font.PLAIN, 20); 
        legend.setItemFont(font3); 
        legend.setPosition(RectangleEdge.BOTTOM); 
        chart.addLegend(legend); 

2
最快找到答案的方法是阅读API文档(http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/axis/CategoryAxis.html),并扫描所有的setXXX()方法(包括继承的方法)。setLabelFont()应该会引起你的注意,值得一试。 - David Gilbert
请参见Help with font size please - trashgod
1个回答

32

使用

CategoryPlot plot = chart.getCategoryPlot();
Font font3 = new Font("Dialog", Font.PLAIN, 25); 
plot.getDomainAxis().setLabelFont(font3);
plot.getRangeAxis().setLabelFont(font3);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接