Right Outer Join

2 May 2009

Limiting pie pieces

Filed under: iReport — Tags: , — mdahlman @ 00:26

Pie charts are only useful if there aren’t too may slices in the chart. They work perfectly to show voting results like Obama – 53%, McCain 46%, Other 1%. But when the raw data has more detail, the chart gets messy.

Too Much Detail

Too much detail to read easily

It gets slightly annoying to show Nader, Barr, Baldwin, and McKinney with their percentages. They add no real value, and they significantly detract from the overall effect. It would be ridiculous to show the 226,979 write-in candidates. By default iReport and JasperReports will show all of your values in a pie chart; this a perfectly reasonable default. But it’s not perfect.

Often displaying all of the data in a pie chart is not what’s needed. In the past it was possible to override this default, but it wasn’t convenient. Either you customized your query manually to return only the data that you wanted to use in the chart, or you had to create a chart customizer to provide additional logic.

Starting with JasperReports 3.5 it’s as easy as you could hope to get the perfect pie chart. You can limit the chart to a maximum of N slices, or you can limit it to only slices that are larger than x%.

Pie chart limiting options

Pie chart options (click for full size image)

Here I set the chart to only display section of the pie chart if the section is at least one percent of the total. This way the pie allows us to focus on only the major categories. It’s much easier to immediately make sense of the information this way. The result is shown below.

Correct level of detail

The correct level of detail draws attention to the important information

Finally, I combine the pie chart with a table for the complete report. While the pie chart is best for larger percentages, the table is perfectly suited to include more detailed information. The final chart sets the label format to add the percentage information, and combines the best of charts and tables. A chart like this has been possible in iReport for years, but it’s only with the latest release that it can be done in a minute and without any coding. It’s a great new feature.

Final Report

Final Report

Update: I’ve had a few requsts to see the .jrxml file used to generate the report. Here it is. The very simple SQL query has been tested with MySQL and PostgreSQL; it should work well with other databases as well.


Leave a Comment »

No comments yet.

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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: