Jump to content

reversing dataset order for chart


jkemper

Recommended Posts

I have a requirement to display a report with the data in DESC order with a bar chart that displays the data in ASC order.

 

I would like to do something like this but Im not sure where I would declare this expression.

 

JRDataSource newDataSource = java.util.Collections.reverse($P{REPORT_DATA_SOURCE})

 

Is this the right way to go, or is it possible to reverse the order of the dataset inside a JRChartCustomizer?

 

thx

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

i figured out a way to do this.

 

1. split the chart out into a subreport that takes a datasource of new ...JRCollectionDataSource($V{reportData})

2. put dataset into map of params and declare the parameter $P{reportData}

3. create a variable $V{reportData} that has an expression of com.mycompany.ListUtil.reverseList($P{reportData})

4. create class ListUtil -- i couldn't find anything in the jdk or apache commons that took a list reversed it and returned a new list which is seems most jasper expressions require a return value. So i created this wrapper util.

Code:

public class ListUtil {
public static List reverseList(List listToReverse) {
Collections.reverse(listToReverse);
return listToReverse;
}
}
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...