Jump to content
We've recently updated our Privacy Statement, available here ×

Grouping integer data


pawel_r

Recommended Posts

Hi

I have following problem:

My query returns some integer data (like number of users) and I would like to show this data (in form of list and chart), but in groups, not just as they are (e.g. 0 users=Count, 1-5 users=Count, 5-20 users=Count and so on). How can I extract such data from my report in jasperreport? I would also like to generate dynamically labels for those data (in form as I described).

As for now I was just able manually create 4 variables and assigned for each condition, which when is true, return 1, otherwise null. By counting those variables I get what I wanted in report (however it's time consuming -definitely not for larger groups which I am aiming at). Unfortunatelly I didn't find a way to put those data (single values, not one variable) into chart series.

Code:
		<variable name="userNumber0" class="java.lang.Integer" calculation="Count">	<variableExpression><![CDATA[( $V{user_nr}==0 ? 1 : null )]]></variableExpression></variable><variable name="userNumberMax3" class="java.lang.Integer" calculation="Count">	<variableExpression><![CDATA[( $V{user_nr}>0&&$V{user_nr}<=3 ? 1 : null )]]></variableExpression></variable><variable name="userNumberMax5" class="java.lang.Integer" calculation="Count">	<variableExpression><![CDATA[( $V{user_nr}>3&&$V{user_nr}<=5 ? 1 : null )]]></variableExpression></variable><variable name="userNumberPowyzej5" class="java.lang.Integer" calculation="Count">	<variableExpression><![CDATA[( $V{user_nr}>5 ? 1 : null )]]></variableExpression>
Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

For now the only solution I found in order to get a chart was to prepare new variable (String) and based on multiple condition put data into correct categories. Then I prepared Report Group based on this variable and used reportGroup_count variable as value.

Works fine, but it is really time consuming when you have more categories for data and it is not elastic at all - small change into categories makes you rewrite whole expression (like changing categories from 0-1, 1-5, and so on into 0,1-4, and so on).

 

Someone know better solution?

Link to comment
Share on other sites

Actually, you are right, I haven't thought about any existing solution (probably because jasperreports is my first reporting system).

 

How I imagine that? Well, the most tedious part is writing those conditions, so in perfect world I would like to have some field, when I can simply write all categories (especially when I think about numbers -the most intuitive would be simply giving intervals like 0,1-5,5-20,20-100).

 

On the other hand - this solution is quite good. The only issue is that when I was trying to put some more java code(anonymous classes, some functions, etc.) in variable value I get exception that I shouldn't use fancy Groovy features since they are not managed by ireport. Well, I don't know Groovy so I don't think I was using its structure (well, I heard that Groovy is java extension so I am using it only as far as java goes) and it makes me a little confused. But that's maybe for other topic ...

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