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

Pie chart problem


rapthor

Recommended Posts

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()>1

Value 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()>1

From 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:36



Post Edited by rapthor at 11/13/2009 09:49
Link to comment
Share on other sites

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

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()>-11
ATC_VALID_GROUP ===>>> $V{DAYS_TILL_EXPIRATION}!=null&&$V{DAYS_TILL_EXPIRATION}.longValue()>-11
ATC_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

Hi,

I'm sorry, that I didn't understood your first post the right way.  /tools/fckeditor/editor/images/smiley/msn/embaressed_smile.gif

I 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

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

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) ? "" : null

I 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:05



Post Edited by rapthor at 11/16/2009 14:08

Link to comment
Share on other sites

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) ? "" : null

Again 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

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) ? "" : null

Unfortunately, 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

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