display the bars in each catergory together without gap betw

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Post Reply
Hari

display the bars in each catergory together without gap betw

Post by Hari » Tue Mar 21, 2006 11:38 am

Hi,
I have a bar graph with category data set.Can someonehelp me find away in which I can display the bars in each catergory together without gap between them.And how can I chage the color of the bars to suit my needs.

Thanks in Advance 8)
Hari

My Code for reference

String series1 = "Self Mark";
String series2 = "Overall Mark";
// column keys...
String category1 = "Benevolent";
String category2 = "Critical";
String category3 = "Developmental";
// create the dataset...
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(10, series1, category1);
dataset.addValue(10, series1, category2);
dataset.addValue(80, series1, category3);

dataset.addValue(20, series2, category1);
dataset.addValue(10, series2, category2);
dataset.addValue(70, series2, category3);

JFreeChart barChart=ChartFactory.createBarChart
(
"BarChartDemo",

"Category",

"Value",

dataset,

PlotOrientation.VERTICAL,

true,

false,

false

);

CategoryPlot plot = barChart.getCategoryPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setDomainGridlinePaint(Color.white);
plot.setDomainGridlinesVisible(true);
plot.setRangeGridlinePaint(Color.white);
BarRenderer renderer = (BarRenderer)plot.getRenderer();
//to control spacing, adjust accordingly

renderer.setItemMargin(0.00010);

renderer.setMaximumBarWidth(0.05);

renderer.setSeriesPaint(0, Color.white);
renderer.setSeriesPaint(1, Color.black);

try {

ChartUtilities.saveChartAsPNG(new java.io.File("C:\\hari2.png"), barChart, 500, 300);

} catch (java.io.IOException exc) {

System.err.println("Error writing image to file");

}
}

}

tal
Posts: 8
Joined: Fri Mar 24, 2006 4:48 pm

Post by tal » Fri Mar 24, 2006 4:50 pm

Try this:

renderer.setItemMargin(0);

Tal

Post Reply