Remove space between bars in a horizontal bar Graph

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
skalluraya
Posts: 15
Joined: Fri Jan 23, 2009 5:36 am

Remove space between bars in a horizontal bar Graph

Post by skalluraya » Sat Jan 24, 2009 8:15 am

Hi,

I have a horizontal bar chart which compare match score details three Teams. I have Match Category in one category axis and score in value axis .

Now i have got a bar chart But by default there is space between horizontal bars. I want a set of score of three teams for a match to come together i.e i want no space between set of values for a category then after 3 values are over i want some space and then display then set of value for next category.

I could not find the which function does that. Can any one help me

One similar Graph

[img]http://www.developer.com/img/2007/12/PHPChart2.gif[/img]


My Code is:


import java.awt.Color;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;

import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.general.DatasetUtilities;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

public class BarChart1 extends ApplicationFrame {

public BarChartDemo2(String title) {
super(title);

CategoryDataset dataset = createDataset();
JFreeChart chart = createChart(dataset);

ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(600, 350));
setContentPane(chartPanel);
}

private CategoryDataset createDataset() {
final double[][] data = new double[][] {
{1,2,3,1},
{1,2,3,1}
};
return DatasetUtilities.createCategoryDataset("Team ", "Match ", data);
}

private JFreeChart createChart(final CategoryDataset dataset) {

final JFreeChart chart = ChartFactory.createBarChart(
"Score Bord", "Match", "Score", dataset,
PlotOrientation.HORIZONTAL, true, false, false);

chart.setBackgroundPaint(new Color(249,231,236));

CategoryPlot plot = chart.getCategoryPlot();

plot.setDomainGridlinesVisible(true);
plot.getRenderer().setSeriesPaint(0, new Color(128, 0, 0));
plot.getRenderer().setSeriesPaint(1, new Color(0, 0, 255));

return chart;
}

public static void main(final String[] args) {
BarChartDemo2 chart = new BarChartDemo2("Score Bord");
chart.pack();
RefineryUtilities.centerFrameOnScreen(chart);
chart.setVisible(true);
}
}

if i set
plot.getDomainAxis().setCategoryMargin(0.0);
then margin is getting 0 but the 1 match dataset of team 2 is joined with 2 match dataset of team 1

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Post by paradoxoff » Sat Jan 24, 2009 12:06 pm

Code: Select all

(BarRenderer(renderer)).setItemMargin(0.0);

skalluraya
Posts: 15
Joined: Fri Jan 23, 2009 5:36 am

Post by skalluraya » Sat Jan 24, 2009 12:12 pm

Thank u sir, it worked.

Locked