如何在JFreeChart中创建XYBarChart,条形之间没有任何空格?我可以使用XYBarDataset.setBarWidth()
手动设置宽度,但通过反复试验,我无法消除差距。
我的图表目前看起来像:
以下代码:
XYSeries series = new XYSeries("XYGraph");
for (int i = 0; i < fileData[0].length; i++) {
series.add(fileData[0][i], fileData[comboNumber][i]);
}
XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(series);
XYBarDataset barDataset = new XYBarDataset(dataset, 13);
JFreeChart chart = ChartFactory.createXYBarChart("Power Profile", "Time (m)", false, "Power (kW)", barDataset, PlotOrientation.VERTICAL, false, true, false);
chart.setBackgroundPaint(null);
XYPlot plot = (XYPlot) chart.getPlot();
ValueAxis yAxis = plot.getRangeAxis();
yAxis.setRange(0, findPeak(0, fileData[0].length, 0, fileData.length, -1, true).getValue() + 5);
plot.setBackgroundPaint(Color.white);
plot.setRangeGridlinesVisible(true);
plot.setDomainGridlinesVisible(true);
plot.setRangeGridlinePaint(Color.black);
plot.setDomainGridlinePaint(Color.black);
panel.removeAll();
panel.setLayout(new java.awt.BorderLayout());
ChartPanel CP = new ChartPanel(chart);
CP.setSize(panel.getSize());
panel.add(CP,BorderLayout.CENTER);
panel.validate();
this.repaint();
附加说明:要绘制的条形数量不断变化。