Jump to content

Strange Pie chart problem


ujbi

Recommended Posts

Hello,

 

I've made a small test report that consists of a pie chart and a table to display election results.

Each label of the chart should display the party followed by the percentage of the election result.

Below the details table is a textfield that displays the total of all votes. See attached image.

The chart is generated correct, also the total of the votes is calculated correct and displaxed in the textfield, but the percentages in the chart labels are wrong. As you can see the value is the votes of the party devided by the current value of the variable the holds the total.

Maybe the reason are some wrong evaluation attributes of the chart and the variable ? Below are some code snippets of my jrxml.

 

TIA

Gernot

 

--------------------------------------------------------

<variable name="totalVotes" class="java.lang.Integer" resetType="Group" resetGroup="chartGroup" calculation="Sum">

<variableExpression><![CDATA[$F{votes}]]></variableExpression>

<initialValueExpression><![CDATA[new Integer(0)]]></initialValueExpression>

</variable>

...

...

...

<group name="chartGroup" >

<groupExpression><![CDATA[null]]></groupExpression>

<groupHeader>

<band height="300" isSplitAllowed="true" >

<pieChart>

<chart isShowLegend="false" evaluationTime="Report" evaluationGroup="chartGroup" hyperlinkTarget="Self" >

...

...

...

<labelExpression><![CDATA[$F{party} + " " + new Float(($F{votes}.floatValue()/$V{totalVotes}.floatValue()) * 100f) + "%"]]></labelExpression>

...

...

...

<textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Report" hyperlinkType="None" hyperlinkTarget="Self" >

<reportElement

x="258"

y="0"

width="252"

height="20"

key="textField-3"

isRemoveLineWhenBlank="true"/>

<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>

<textElement>

<font/>

</textElement>

<textFieldExpression class="java.lang.Integer"><![CDATA[$V{totalVotes}]]></textFieldExpression>

</textField>

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Sorry, I forgot the image... [file name=MyReport2.jrxml size=7572]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/MyReport2.jrxml%5B/file] size=342]http://www.jasperforge.org/components/com_joomlaboard/uploaded/images/report.PNG
Link to comment
Share on other sites

After some investigation I found out, that the only way to get the pie chart displayed correct is to set its incrementation type to "None" (increment with each record) and evaluation time "Report". In this case, the variable that holds the total does not yet contain the final value. This causes the erroneous label entries.

The only solution I see is to provide a customizer class that sets a special LabelGenerator (PieSectionLabelGenerator) to the PiePlot. This is working job for me.

It would be a gooed idea to have something like an "Auto" evaluation time for charts as it is for textfields.

 

Gernot

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