0

我正在寻找一种方法来改变 JFreechart 中条形图的设计。这是我的excel图表。如何更改以下设计格式的 jfreechart 条形图?

在此处输入图像描述

4

1 回答 1

2

以下代码可以生成类似的图表。够了吗?

条形图示例

public class BarExample {
    public static void main(String arg[]) throws IOException {
        DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
        dataSet.setValue(2, Integer.valueOf(1), Integer.valueOf(5));
        dataSet.setValue(7, Integer.valueOf(1), Integer.valueOf(10));
        dataSet.setValue(4, Integer.valueOf(1), Integer.valueOf(15));
        dataSet.setValue(9, Integer.valueOf(1), Integer.valueOf(20));
        dataSet.setValue(6, Integer.valueOf(1), Integer.valueOf(25));
        JFreeChart chart = ChartFactory.createBarChart
                ("Chart", "Number of Days", "Number of ECR", dataSet,
                        PlotOrientation.VERTICAL, false, true, false);
        CategoryPlot plot = chart.getCategoryPlot();
        // Reduce margin between bars
        plot.getDomainAxis().setCategoryMargin(0.0);
        // Reduce left and right margin
        plot.getDomainAxis().setLowerMargin(0.0);
        plot.getDomainAxis().setUpperMargin(0.0);
        FileOutputStream outputStream = new FileOutputStream(
                new File("chart.png"));
        ChartUtilities.writeChartAsPNG(outputStream, chart, 1024, 768);
    }
}
于 2013-04-16T16:24:13.247 回答