1

I am using JFreeChart for displaying Bar Graph, the width of the bars in the graph is huge. I want to reduce the width of the bars, is there any API for it, please let me know..

Ankush soni
  • 1,439
  • 1
  • 15
  • 30
Asif
  • 23
  • 1
  • 6

1 Answers1

-1
BarRenderer renderer = (BarRenderer) chart.getCategoryPlot().getRenderer();
renderer.setItemMargin(-2);

Try the above code. Try to look at this thread as well.

Width of the bar in Jfreechart

Please note above snippet is from same thread.

As an answer to your comment following is the Java Doc for the same method

public void setItemMargin(double percent)
Sets the item margin and sends a RendererChangeEvent to all registered listeners. The value is expressed as a percentage of the available width for plotting all the bars, with the resulting amount to be distributed between all the bars evenly.
Parameters:
percent - the margin (where 0.10 is ten percent).
Community
  • 1
  • 1
Jabir
  • 2,776
  • 1
  • 22
  • 31
  • yes I tried it but it doesn't work with renderer.setItemMargin(-2); with this code the bars just get disappeared but when I changed it to renderer.setItemMargin(.10); its done the size got reduced by half. I want to know what the parameter of this method do? – Asif Aug 03 '15 at 11:55
  • BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setMaximumBarWidth(.10); This line of code solved my problem. – Asif Nov 07 '15 at 10:01