Jump to content
Changes to the Jaspersoft community edition download ×

SOLUTION: Retain Query/Datasource Level Sorting HTML5 Charts


StevenCrawford
Go to solution Solved by StevenCrawford,

Recommended Posts

 

I was frustrated by the default sorting order on the HTML5 charts.  To customize the sort order you must create a comparator. And even then you can only sort by a category or series, not by a measure!   I wanted to be able to sort my data in the query to solve these problems.  The GUI provided no solutions besides the limited ascending or descending selections.  
 
The Soltuion:
Create a  comparator which always returns a value of 1 (greater than).  iReport sees that the data is already in order and doesn't change anything.  This allows you to define ordering at the query level!  See the attached java file for more info. I've also attached a jar if you just want the fix.
 
To use:
Add jar to classpath.
Instantiate the custom comparator in the Comparator Expr box for the desired series or category.  Enjoy query level sorting!
Link to comment
Share on other sites

  • 3 weeks later...
  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

  • Solution
*EDIT 2*

As of Jasper 5.1, I believe Jaspersoft fixed this issue by adding a 'none' sort type.  I have not tried this due to time constraints but it's worth a shot if you're on 5.1 or later.

 

*EDIT 1*

My orginal solution worked fine for data sets that only had one measure per category.  Basically any data set that didn't have the category repeated more than once.  However when the category value was repeated it viewed everything as larger than the value before it.  The solution wasn't as obvious as it should have been but I simply added a check in the Comparator to detect if the two objects were equal.  If they were then I return 0, otherwise return 1 as usual.

 

The Soltuion:

Create a  comparator which always returns a value of 1 (greater than).  iReport sees that the data is already in order and doesn't change anything.  This allows you to define ordering at the query level!  See the attached java file for more info. I've also attached a jar if you just want the fix.

 

To use:

Add jar to classpath.

Instantiate the custom comparator in the Comparator Expr box for the desired series or category.  Enjoy query level sorting!

 

 

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