How do I create an XYBarChart in JFreeChart without any space between bars? I can manually set the width using XYBarDataset.setBarWidth()
but though trial and error, I have been unable to remove the gap.
My chart currently looks like:
Code below:
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();
Additional note: the number of bars to be plotted is constantly changing.