Gap between bars of same series

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Mailkr
Posts: 2
Joined: Thu Nov 12, 2009 12:33 am
antibot: No, of course not.

Gap between bars of same series

Post by Mailkr » Thu Nov 12, 2009 12:41 am

Trying to create bar chart with 2 series items.
I am setting the setItemMargin to 0.0 on BarRenderer for no gap between the bars.
If i have only one item(2-series) on the bar then it adds the gap between the bars, But if have multiple items then it doesn't have gap between the series bars.

Don't know how i am getting the gap..
Do you have any clue?

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Gap between bars of same series

Post by david.gilbert » Thu Nov 12, 2009 6:29 am

It comes from the CategoryAxis and you can control it with setCategoryMargin().
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

abhinav.mishra
Posts: 10
Joined: Mon Jan 11, 2010 6:54 am
antibot: No, of course not.

Re: Gap between bars of same series

Post by abhinav.mishra » Fri Jan 15, 2010 6:20 am

I think Mailkr wants to reduce the gap between the bars that belong to the same category and not the gap between the different categories.
Is it true?

Because I am also facing the same problem.
I can reduce the gap between the different categories but not between the bars of same category.
Is there any function or any other workaround in jfreechart to achieve that?

Thanks in advance,
Abhinav

link101
Posts: 1
Joined: Fri Jan 15, 2010 4:38 pm
antibot: No, of course not.

Re: Gap between bars of same series

Post by link101 » Fri Jan 15, 2010 5:26 pm

Stacked bar(column) charts are a popular way to depict 2 more series of related data, like sales of 2 products.But there are several ways to stack the bars in a bar chart. Hard to compare, only first value starts at zero, takes more space, needs extra calculation for the gap series, needs extra calculation, One series dominates another, good where domination is needed, Needs extra formatting, not always produces good results, difficult to compare, needs extra formula to calculate gap series.
____________
stocktake

ShashankRaj
Posts: 5
Joined: Fri Aug 27, 2010 7:57 am
antibot: No, of course not.

Re: Gap between bars of same Category

Post by ShashankRaj » Wed Sep 01, 2010 6:00 am

I am facing the same issue with adjusting the gaps between the same category ,setCategoryMargin() does not seem to work at all ,if we are having two series for the same category,niether adjusting the BarRender class is comfortable,there should be some way to deal with this problem, or either please suggest a code , to adjust the BarRenderer Class to get the required output

azrael
Posts: 9
Joined: Fri Jan 20, 2012 1:02 pm
antibot: No, of course not.
Location: Germany

Re: Gap between bars of same series

Post by azrael » Mon Jan 23, 2012 12:49 pm

Still no solution?

I'm having the same problem, using a XYPlot an a XYBarRenderer to generate my bars. And obvious there's no chance to divide my bars, as long as they are in the same series.

also, if I'm not totally wrong, I'm even not having a CategroyAxis to use setCategoryMargin() in any way:

Code: Select all

		
	XYPlot plot = new XYPlot(
			dataSetBar,
			new DateAxis(dateAxisLabel),
			new NumberAxis(valueAxisLabel),
			new DifferenceBarRenderer(
							getPositiveColor(),
							getNegativeColor(),
							getThreshold()));

		JFreeChart result = new JFreeChart(getTitle(), getFont(), plot, true);
As you can see, I'm generating Bars für date values on a DateAxis. But I've already overwritten the XYBarRenderer to show different colors on positive or negative values, so any additional override to insert a gap ist a welcome solution...

anyone any idea?

azrael
Posts: 9
Joined: Fri Jan 20, 2012 1:02 pm
antibot: No, of course not.
Location: Germany

Re: Gap between bars of same series

Post by azrael » Mon Jan 23, 2012 1:15 pm

Somedays... looking for a solution for days and finding only post asking the same question an no answer... Now, after viewing and seraching the code for another time, I've found the solution:

For a BarRenderer, you can call the method setItemMargin(double percent) - the equvalent to this method on XYBarRenderer seems to be setMargin(double percent).

sorry for exhuming this old post...

kumari
Posts: 1
Joined: Fri Jun 22, 2012 11:10 am
antibot: No, of course not.

Re: Gap between bars of same series

Post by kumari » Fri Jun 22, 2012 11:31 am

HI everyone
I too ahve same issuse
i tried using plt.getDomainAxis().setCategoryMargin(0.00);
as well as StackedBarRenderer renderer = (StackedBarRenderer) chart.getCategoryPlot().getRenderer();
renderer.setItemMargin(0);
for my stacked bar chart
nothing is working fine for sme.
it will be helpful if am able to resolve this
Thanks in advance

Locked