Right Outer Join

20 May 2009

Axis Min and Max values

Filed under: iReport — Tags: , , , — mdahlman @ 17:23

Axis Min and Max values

A common request when creating charts is to fix the minimum and maximum values for the vertical axis┬╣. One common reason for doing this is that the position of the line within the chart conveys important meaning. The default behavior is to plot the smallest data point at the lowest point and the largest data point at the highest point. It’s great default. But sometimes the axis should display 0 to 100 regardless of what the data values are.

In the chart below I invented downtime statistics for a server I’m administering. It was unavailable for one hour on Wednesday. One hour corresponds to 3,600,000 milliseconds, or about 4% of a 24 hour day. This chart nicely shows how downtime spikes on Wednesday. But the chart fails to put into perspective the idea that 4% is relatively small compared to 100%.

The vertical axis automatically adjusts to the data

The vertical axis automatically adjusts to the data

It has always been possible to create a chart customizer that forces the axis min and max. But this is not a pleasant option for new users as it requires knowledge of Java and of JFreeChart. Starting with iReport 3.5 (and the corresponding JasperReports 3.5) it’s as easy to set these values as it should be.

In the chart below I have set the min and max to 0 and 1. Now we see visually how the downtime is small. The corresponding trade off is that the chart is able to show less precision between the different values. In this case I’m happy with the trade off. I want to focus on the fact that downtime was minimal.

More importantly, it took me approximately 5 seconds to set the min and max values for this chart. This is a huge benefit compared with the prospect of writing a Java class in order to set this property.

The vertical axis is forced to run from 0 to 100%

The vertical axis is forced to run from 0 to 100%

Sysadmins out there who target 5 9′s or more may scoff at my claim that one hour of downtime isn’t much. (5 9′s corresponds to 99.999% uptime.) But of course the point is that there are times when using fixed axes is desirable.

Other reasons for wanting fixed axes include reports that serve a dashboarding function. With these we need to very quickly identify if lines (or bars) fall into acceptable ranges. If the range on the chart may be different depending on the data, then it will require more effort to assess if the values are acceptable. Likewise, if I place two charts next to each other it’s common that I’ll want to make comparisons between them. Forcing the min and max values for the axes allow me to do this.

Now that this ability has gone from possible to dead easy, I think we’ll see a lot more Jaspersoft users taking advantage of it.

┬╣ Although I wrote “vertical axis”, this is not quite correct. Line and bar charts can display vertically or horizontally. The axis I want to fix is therefore not necessarily the vertical axis. More formally the horizontal axis in my examples is called the category axis, and the vertical axis is called the value axis or range axis. For this reason the properties that I set in iReport are called “Range Axis Min Value Expression” and “Range Axis Max Value Expression”.

About these ads

7 Comments »

  1. In your Axis Min and Max values column.
    Can you please give me a detailed on how to implement this one? I tried to use Axis Min and Max values expression, but I guess old version (3.1.5) doesn’t support this feature.
    And when I tried to update the jar file to 3.5 some report didn’t worked.

    any response is much appreciated.
    Tnx.

    Comment by Lexx — 25 May 2009 @ 21:08

  2. Lexx,

    You are correct: this feature was added in JasperReports 3.5.0 (and iReport 3.5.0), so it’s not available in 3.1.5. I’ll update the article to be more explicit about that.

    If you use iReport, as I do, then you need to update to the 3.5.0 or later. Then you’ll see the options. Get the full install or the .zip package. (Updating just the jasperreports.jar file within iReport won’t work.)

    If you’re using JR without iR, then you should be able to swap out the old jar file, replace it with the new 3.5 jar file, and things should work. (WordPress doesn’t seem to allow XML in comments, so I’ll see if I can update the article to show the code for someone using JasperReports without iReport.)

    In general JasperReports is very very good about being backwards compatible. So I would expect old reports to continue working correctly with the new jar file. You should test, of course. And report bugs if you find any. But in my experience this backwards compatibility is very solid.

    Regards,
    Matt

    Comment by mdahlman — 26 May 2009 @ 07:10

  3. Thanks for the reply.

    By the way, is there’s any other option to use Axis Min and Max value expressions aside from updating the jar file to latest version? How about using Customizer Class is this one the best option?

    tnx.

    Comment by Lexx — 26 May 2009 @ 18:40

    • Yes, using a chart customizer is your only option if you are using JasperReports 3.0 or older. Starting with iReport/JasperReports 3.1 chart customizers are deprecated in favor of Chart Themes.

      Starting with iR/JR 3.5… setting the min and max is easy.

      Comment by mdahlman — 28 May 2009 @ 15:51

  4. Hi Matt,

    Can you please explain bit about how to use chart customizer to Set Min and MAx values. and i like to know, is there any option to number the Y axis continuously without having range values.

    Appreciate your help

    thnx
    Keth

    Comment by Keth — 7 October 2009 @ 21:37

  5. hello Matt,

    Another question for you. hope you could help me on this.In my Line chart i have 2 category serieses(“Ordered” vs “Sales”). using Chart customizer we could obtain a reference to the plot as follows

    public void customize(JFreeChart chart, JRChart jasperChart) {
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) chart.getCategoryPlot().getRenderer();
    //renderer.setSeriesPaint(1, Color.green);
    //renderer.setSeriesPaint(4, Color.orange);

    // get a reference to the plot for further customisation…
    final CategoryPlot plot = chart.getCategoryPlot();

    But this time i want to get a reference to above mentioned series categories. Do you have any idea about this?

    appreciate your help

    Thanks,
    keth

    Comment by Keth — 26 October 2009 @ 00:14


RSS feed for comments on this post. TrackBack URI

Go on... 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

The Silver is the New Black Theme. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 36 other followers

%d bloggers like this: