Search code examples
jfreechartbar-chart

JFreeChart BarChart setUpperMargin to next interval?


I am using JFreeChart to create a BarChart. My question: is there a way to set the uppermargin of the graph to stop at the next interval? As an example, say a Bar Graph is made with range intervals of 5. Say the tallest bar ends at 30. Is there a way automatically set margins to make the graph go vertically until 35-the next interval? I know there is a setUpperMargin method but that requires inputting double values until one achieves the upper range he wants. Instead, is there a way to just set the margin to go for another interval after the end of the bar graphs? Thank you.


Solution

  • Query your chosen CategoryDataset for the maximal range value and use setUpperBound() on the range axis. BarChartDemo1, included in the distribution, shows how to reference an axis.