gpt4 book ai didi

java - JFreeChart 条形图设计变更

转载 作者:行者123 更新时间:2023-12-02 07:06:32 27 4
gpt4 key购买 nike

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

enter image description here

最佳答案

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

bar chart example

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);
}
}

关于java - JFreeChart 条形图设计变更,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16040776/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com