rapthor Posted November 13, 2009 Share Posted November 13, 2009 Hello,I am trying to fill a pie chart with data that is based on group processing. I attached a picture of my wrong pie chart to this thread. The pie chart is placed in the summary band next to other charts containing group usage.The Detals tab of the pie chart looks as follows:Key expression:$V{DAYS_TILL_EXPIRATION}!=null&&$V{DAYS_TILL_EXPIRATION}.longValue()>1Value expression:$V{ATC_VALID_GROUP_COUNT}Label expression:$V{ATC_VALID_GROUP_COUNT}As you can see I am using a boolean expression for the key. So there should be 2 slices representing true and false. Furthermore, the value itself should be the number of true and false results by the same expression, which is again defined in the group called ATC_VALID_GROUP.ATC_VALID_GROUP contains the same expression used for the key above:$V{DAYS_TILL_EXPIRATION}!=null&&$V{DAYS_TILL_EXPIRATION}.longValue()>1From what I understood, the implicit variable $V{ATC_VALID_GROUP_COUNT} should contain the number of occurences of the group true or false.The resulting pie chart looks strange: It has 2 slices BUT they are labelled 1 and 79 and their values seem to be the same. The dataset I am working on contains hundreds of records and therefore hundreds of $V{DAYS_TILL_EXPIRATION}, so I would expect something like 280 true and 800 false.I am SURE the variable $V{DAYS_TILL_EXPIRATION} is based on a record field and contains java.util.Long numbers.What is wrong with the way I am processing the records?Post Edited by rapthor at 11/13/2009 09:36Post Edited by rapthor at 11/13/2009 09:49 Link to comment Share on other sites More sharing options...
ckampshoff Posted November 13, 2009 Share Posted November 13, 2009 Hi rapthor,it prints the 1 and the 79, because of your Label expression. It prints the Value of $V{ATC_VALID_GROUP_COUNT}.RegardsChristina Link to comment Share on other sites More sharing options...
rapthor Posted November 15, 2009 Author Share Posted November 15, 2009 Hi Christina,thanks for the quick reply BUT as mentioned, the key expression of the pie chart exactly matches the group expression the variable ${ATC_VALID_GROUP_COUNT} belongs to:PIE CHART KEY EXPRESSION ===>>> $V{DAYS_TILL_EXPIRATION}!=null&&$V{DAYS_TILL_EXPIRATION}.longValue()>-11ATC_VALID_GROUP ===>>> $V{DAYS_TILL_EXPIRATION}!=null&&$V{DAYS_TILL_EXPIRATION}.longValue()>-11ATC_VALID_GROUP_COUNT ===>>> [the number of elements in the groups that are built on my boolean expression?] So, why is $V{ATC_VALID_GROUP_COUNT} giving me 1 and 79 although I am absolutely sure it should be about 210 and 830 for my test data? The test data has about 1040 results. Shouldnt 1 and 79 be equal to the result of occurences of TRUE and FALSE of my pie chart key expression?I really appreciate any response that helps me a bit :))Thanks. Link to comment Share on other sites More sharing options...
ckampshoff Posted November 16, 2009 Share Posted November 16, 2009 Hi,I'm sorry, that I didn't understood your first post the right way. /tools/fckeditor/editor/images/smiley/msn/embaressed_smile.gifI got another idea. What about the evaluation time of the pie chart? Perhaps it should be set to 'report'. If this isn't the right thought you might post your jrxml so that we can have a look.HTH Christina. Link to comment Share on other sites More sharing options...
Giulio Toffoli Posted November 16, 2009 Share Posted November 16, 2009 I think you should just change the approach to fill the pie chart.1. Create two variables, one to collect trues, the other to collects falses.2. Print the two values in the summary (this is options, but in this way you can be sure the two values are ok.3. Create a pie chart with 2 series: the first has as key "TRUE" and use as value the variable to holds the trues, the second has key "FALSE" and uses as value the other variable. Giulio Link to comment Share on other sites More sharing options...
rapthor Posted November 16, 2009 Author Share Posted November 16, 2009 Hello again,I have created a variable that collects TRUE as suggested by giulio:>1. Create two variables, one to collect trues, the other to collects falses.In fact I created a variable called "$V{ATC_VALID_INT}" with "Calculation = Count" and "Reset Type = Report", "Increment type = None", class "Integer" and the following expression:(!$F{ATC_NR}.startsWith("(null)")&&$V{DAYS_TILL_EXPIRATION}!=null&&$V{DAYS_TILL_EXPIRATION}.longValue()>0) ? "" : nullI am using this variable in my pie chart which is positioned in the summary (!) band. The jrxml at this position looks like: <variable name="ATC_VALID_INT" class="java.lang.Integer" calculation="Count"> <variableExpression><![CDATA[(!$F{ATC_NR}.startsWith("(null)")&&$V{DAYS_TILL_EXPIRATION}!=null&&$V{DAYS_TILL_EXPIRATION}.longValue()>0) ? "" : null]]></variableExpression> <initialValueExpression><![CDATA[]]></initialValueExpression> </variable>Unfortunately, the variable seems to result in 0. I even checked it in the details band, where for each record the value keeps 0 even though it should count up to a value of 2 (I am using test data which is reduced to 4 records for which 2 records should return true for the above expression).Is there a problem with mixing up fields and variables in my new variable definition?Furthermore I got the feeling that sometimes I get different results for variables between restarts of iReport ...Any help is appreciated .... :(Here is the excerpt of the pie chart: <summary> <band height="526"> <pieChart> <chart isShowLegend="false" evaluationTime="Report"> <reportElement x="14" y="10" width="256" height="175"/> <chartTitle> <font size="12" isBold="true"/> <titleExpression><![CDATA["ATCs valid/expired"]]></titleExpression> </chartTitle> <chartSubtitle/> <chartLegend/> </chart> <pieDataset> <pieSeries> <keyExpression><![CDATA["Valid"]]></keyExpression> <valueExpression><![CDATA[$V{ATC_VALID_INT}]]></valueExpression> <labelExpression><![CDATA["Valid ("+$V{ATC_VALID_INT}+")"]]></labelExpression> </pieSeries> </pieDataset> <piePlot isCircular="true"> <plot> <seriesColor seriesOrder="0" color="#FF3333"/> </plot> <itemLabel color="#000000" backgroundColor="#FFFFFF"/> </piePlot> </pieChart> </band> </summary>Post Edited by rapthor at 11/16/2009 14:05Post Edited by rapthor at 11/16/2009 14:08 Link to comment Share on other sites More sharing options...
Giulio Toffoli Posted November 17, 2009 Share Posted November 17, 2009 The approach seems perfect, so the problem must be with your expression, which is correct in terms of syntax, but probably it results always in a null...(!$F{ATC_NR}.startsWith("(null)")&&$V{DAYS_TILL_EXPIRATION}!=null&&$V{DAYS_TILL_EXPIRATION}.longValue()>0) ? "" : nullAgain my suggestion is to print out each field for each detail to see the right values, and print out the variable value to see what's wrong.Giulio Link to comment Share on other sites More sharing options...
rapthor Posted November 17, 2009 Author Share Posted November 17, 2009 Hey,thanks for looking at the code. I put the variable in the details band to see its value on each record and I noticed something. Within the expression I am using a field and a variable.(!$F{ATC_NR}.startsWith("(null)")&&$V{DAYS_TILL_EXPIRATION}!=null&&$V{DAYS_TILL_EXPIRATION}.longValue()>0) ? "" : nullUnfortunately, the variable $V{DAYS_TILL_EXPIRATION} I am using has not been processed yet when the expression is first processed. Hence on every next processing of the expression, this variable contains the result of the former (!) step. The data JasperReports processes therefore is inconsistent. So everything is somehow shifted and this is why I see strange results. The field value $F{ATC_NR} is always current, but that's not the case for the variable $V{DAYS_TILL_EXPIRATION} in the same expression :(What I did is replacing the variable in the expression by its definition, which leads to redundancy because I am using the same definition multiple times in the expression and cannot summarize it in a variable anymore. Is there a way to make JasperReports process all variables before actually perform any expression related to these variables?Any other suggestion?I hope it is clear what I wonder about.Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now