My question is very similar to the question asked in this SO link
Create barchart using jfreechart with bars of same category together
If I run the below example, I get the chart as an image, (image attached)
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();
}
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)
BarRenderer br =(BarRenderer) plot.getRenderer() ;
br.setItemMargin(0.0);
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.