Setting custom range for your plot within JFreeChart

My data had Y-values that were all around the 1.217 to 1.219 billion data range; however, JFreeChart was auto calculating the proper orientation of the graph and making the range start from zero and end at my highest range value. This makes my data which should look like a slope=1 sideways line look instead like a slope=0 flat line.

JFreeChart has a method in the NumberAxis class called ‘setAutoRangeIncludesZero’ which lets you choose whether to start your range from zero by default. Unfortunately, my ‘RangeAxis’ object was of type ValueAxis, and this class doesn’t have any such method.

Here is the solution:

NumberAxis yaxis = (NumberAxis) chart.getXYPlot().getRangeAxis();

yaxis.setAutoRangeIncludesZero(false);

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s