problem with "COUNT" and creating a chart

i am having trouble getting anything within iReports to work. i am able to do a basic report which displays the value of each field on the page. however, when i try to do any manipulation or calculation with the data, i get errors and nothing works. also, i cannot get the chart tool to work either. any advice/suggestions would be greatly appreciated. we are about at the point where we will have to use a different reporting tool.

scenario 1 -- trying to get a count of the number of records where a particular field equals a specified value

scenario 2 -- trying to get a pie chart which compares the various values/results of a particular drop down field

scenario 3 -- trying to get a sum of order amount for a given range of orders

Code:
scenario 1 -- entered in the variable expression --
$F{cases_priority}.contains( "P1" )
 
scenaro 2 -- entered in the key expression
$F{cases_priority}
 
--entered in the value expression
$F{cases_priority}.contains( "P1" )
 
--entered in label expression
$F{cases_priority}
 
scenario 3 -- not yet tried</td></tr></tbody></table>
tcsbasys's picture
Joined: May 5 2009 - 1:05pm
Last seen: 14 years 4 months ago

7 Answers:

For counting number of records and for getting sum of order amount for a given range of orders you can simply use variables with calculation type Count and sum respectively.
harinderrakkar's picture
Joined: May 5 2009 - 3:27am
Last seen: 10 years 7 months ago

i have tried that BUT the variable expression is not working correctly so i get an error and the count/sum does not work.

the variable i set up  -- count_cases_priority_1 --  has a varible expression of    

$F{cases_priority}.contains( "P1" ) 

but when i try to execute the report using the active conneciton i get an error -- Cannot cast from boolean to Object

 

i am totaly stuck and do not know what else to try or where to go for help. we purchased the "The Ultimate Guide to iReport " but it does not help much.

tcsbasys's picture
Joined: May 5 2009 - 1:05pm
Last seen: 14 years 4 months ago

First of all I strongly suggest you to set as language for the report Groovy (in the report properties). In this way you can forget about the complexity of some expression with Java.

scenario 1 -- entered in the variable expression --

a) Create a new variable
- Class:  Integer (we are doing a count)
- Calculation: Count
- Variable expression:  $F{cases_priority}.contains( "P1" ) ? $F{cases_priority} : null
- (Optional) Initial Value Expression: 0

Just a note about the variable expression: the count calculation add 1 if the expression is not null, 0 otherwise, so the if condition return something that is supposed to be not null ($F{cases_priority}) if $F{cases_priority} contains P1 otherwise return null.

scenario 2 -- trying to get a pie chart which compares the various values/results of a particular drop down field

Not sure what do you mean.,,,

scenario 3 -- trying to get a sum of order amount for a given range of orders

a) Create a new variable
- Class:  Double
- Calculation: Sum
- Variable expression:  $F{myAmountFiled}
- (Optional) Initial Value Expression: 0.0

Giulio

 

giulio's picture
74157
Joined: Jan 2 2007 - 4:15pm
Last seen: 3 days 22 hours ago

your suggestions on scenario #1 did the trick. it is working now. THANKS!!!

 

for scenario #2 - i want to create a pie chart that shows the total number of each value for cases_priority (those are P1, P2, etc). i have used the following setup --

key expression -- $F{cases_priority} ==> this works and shows the various categories available within the database EXcEPT for categories where there are 0 records matching that category

value expression -- this is where i am stuck -- i just want the chart to use the total count of each category as the value here BUT i cannot get the expression to evaluate correctly. i have an individual count for each category separately (for example 65 occurances of P1) but no way to have it select a category and then count the occurances of that value. i need a way to express a count of each cases_priority and sort by the value of cases_priority (ie. P1, P2, P3, etc).

tcsbasys's picture
Joined: May 5 2009 - 1:05pm
Last seen: 14 years 4 months ago

Create a variable for each Priority field (P1, P2, P3...) to count the occurrences.
Create a pie chart, evaluation time: Report
Edit the chart data:
Increment type: Report
In the details tab click on Use more series. Create series for each Priority, using the priority name as key (like "P1") and the relative variable value as value.

That's it.

Giulio

giulio's picture
74157
Joined: Jan 2 2007 - 4:15pm
Last seen: 3 days 22 hours ago

i do not have the option to "In the details tab click on Use more series"....please advise.

tcsbasys's picture
Joined: May 5 2009 - 1:05pm
Last seen: 14 years 4 months ago

this is available only from 3.5.0

giulio's picture
74157
Joined: Jan 2 2007 - 4:15pm
Last seen: 3 days 22 hours ago
Feedback
randomness