Jump to content
We've recently updated our Privacy Statement, available here ×

how to set y-axis scale for BarChart


hklow

Recommended Posts

can we set the scale of y-axis? or least not to show decimal units when the field/variable returns 0 or 1 or 2? the field/variable is defined as Integer, and it doesn't make sense if the Y axis shows 0.25, 0.5, 0.75...
Link to comment
Share on other sites

  • 6 months later...
  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Setting the scale or any other attributes of the axes is a JFreeChart activity. Here's some customizer code that adjusts the item margins and autoscale zero behaviour, it will provide some hints on where to start

Code:

public void customize(JFreeChart jFreeChart, JRChart jRChart)
{
super.customize(jFreeChart, jRChart);

CategoryPlot plot = jFreeChart.getCategoryPlot();
BarRenderer renderer = (BarRenderer) plot.getRenderer();
ValueAxis axis = plot.getRangeAxis();
if (axis instanceof NumberAxis) {
NumberAxis naxis = (NumberAxis)axis;
Range rng = plot.getDataRange(naxis);
double max = rng.getUpperBound();
double min = rng.getLowerBound();
boolean iz = ((max - min) > (max/5.0));
naxis.setAutoRangeIncludesZero(iz);
naxis.setAutoRangeStickyZero(iz);
}
renderer.setItemMargin(0.0);
}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...