title: Clustering bars in a bar chart with the same category
body: <p>My question is very similar to the question asked in this SO link</p>
  
  <p><a href="https://stackoverflow.com/questions/2025590/create-barchart-using-jfreechart-with-bars-of-same-category-together">Create barchart using jfreechart with bars of same category together</a></p>
  
  <p>If I run the below example, I get the chart as an image, (image attached)</p>
  
  <pre><code>DefaultCategoryDataset dataset = new DefaultCategoryDataset();
  dataset.setValue(2, "Lesson-1", "27-sep-2012");
  dataset.setValue(7, "Lesson-2", "27-sep-2012");
  dataset.setValue(4, "Lesson-3", "27-sep-2012");
  
  JFreeChart chart = ChartFactory.createBarChart(
      "BarChart using JFreeChart", "Student sample", "Marks sample", dataset,
      PlotOrientation.VERTICAL, true, true, false);
  chart.setBackgroundPaint(Color.yellow);
  chart.getTitle().setPaint(Color.blue);
  CategoryPlot plot = chart.getCategoryPlot();
  
  BarRenderer br = (BarRenderer) plot.getRenderer();
  br.setItemMargin(0.7);
  try {
      ChartUtilities.saveChartAsJPEG(new File(
          "D:/jfreeimages/sample.jpeg"), chart, 500, 300);
  } catch (IOException e) {
      e.printStackTrace();
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/1ktm2.jpg" alt="Image which I got after running the code mentioned here"></p>
  
  <p>for the date 27-sep-2012, i need all the bars to be clustered and to be displayed without any gaps. Many of them suggested me to have lesser margin for barRenderer (code below)</p>
  
  <pre><code>BarRenderer br =(BarRenderer) plot.getRenderer() ;
  br.setItemMargin(0.0);
  </code></pre>
  
  <p>but this makes the size of the bar very bigger, I want the size of the bar as in the attached image only. Please help.</p>