Sort the Bars in Your Stack - Ordering the Series in Your Chart

Ordering the Series in Your Charts

Problem

The bars in your stacked bar chart are not in the right order. In all likelihood, the bars are sorted in alphabetical order.

Example

In the screenshot below, the bars in each stack are sorted alphabetically, not according to level.

Solution

  1. Use a numeric value to create the initial chart.

  2. Use Bucket Properties to change the "Name" of your series.

Key Concept: Use the numerical value of your performance levels when you initially create your chart. (If you don't have the numeric value, create it using a variable.)

Step 1: Use the Numeric Value of the Performance Levels to Create Your Chart

If you're experiencing this issue, it's because you used the Performance Level Text to set the "Series Levels" in your chart.

First, change the Series Levels to the numeric equivalent of your performance levels.

  • Double-click on your chart

  • Click Chart Data > Configuration

  • Double-click on your Series Levels

  • Click the Pencil Icon next to Expression to bring up the Expression Editor.

  • If you don't have numeric values, create them using a conditional expression like this:

      $F{Performance Level Text}.equals("Below Basic") ? 1
      :$F{Performance Level Text}.equals("Basic") ? 2
      :$F{Performance Level Text}.equals("Proficient") ? 3
      :$F{Performance Level Text}.equals("Advanced") ? 4
      :null

See Basics of Writing Expressions for more information about writing expressions in Jaspersoft Studio.

Preview your report. The bars in the stack should now be in the right order, but now the label will be showing the numbers instead of the performance level text:

Key Concept: Use Bucket Properties to Change the Name/Label of your Series.

Step 2: Create "name" Bucket Property

  • Double-click on your chart

  • Navigate to Chart Data > Configuration

  • Double-click on Series Levels

  • Click Bucket Properties tab

  • Click Add

  • Set the Property name to name

  • Click the Pencil Icon

  • Set the Property value to the field that contains the performance level text.

  • Click Ok

Step 3: Pass the "name" Bucket Property to the Measure

Like all bucket properties, the "name" bucket property needs to be passed to your measure in order to be applied to your chart.

On the chart's configuration screen,

  • Double-click on your Measure

  • Click Advanced Properties

  • Click Add

  • Use drop-down menu to set Series Contributor to SeriesProperty.

  • Set the Property Name to name (must be all lower-case)

  • Select Use Bucket Value

  • Use the drop-down menu to select your name bucket property

  • Click Ok

Voila! Preview your report. Your bars should remain in the right order, and the labels should now be showing the performance level text.

Last updated