0

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.

pmaurais
  • 734
  • 2
  • 9
  • 30
  • Can you post your code? I think this is more a problem of renderer than of dataset. – Eric Leibenguth Jul 30 '15 at 07:48
  • @EricLeibenguth added. – pmaurais Jul 30 '15 at 12:06
  • I just ran your code (with minor adjustments to add dummy data and a JFrame), and my chart does not have any gap between the bars (seems to be the default behaviour). This is with JFreecharts 1.0.19. Can you post a runnable example isolating your problem so we can reproduce it ? – Eric Leibenguth Jul 30 '15 at 13:23
  • @EricLeibenguth I am running 1.0.19. Posting a runnable example would be difficult, this is just a small piece of the code. I Relive my problem is with the constructor. `new XYBarDataset(dataset, **BAR_SIZE**)` I have, at a minimum 96 bars. Each bar is separated by an X increment of 15 units. – pmaurais Jul 30 '15 at 15:05
  • 1
    @EricLeibenguth on closer inspection I have noted that it is not in fact a gap but the way the coloring on the bars is shaded. – pmaurais Jul 30 '15 at 15:08

0 Answers0