0
votes

I am using Jaspersoft Studio and JasperReports Server, both in v.5.6.0.
I want to create a Pie Chart that shows the percentage of Errors colored in red.

Example:
$V{til_1} = total
$V{state_1} = errors
total:2 - errors:1 => should result in a Pie Chart with 2 Slices -> 50% Red and 50% Green.


I used 2 Series, one Serie (Keyexpression) "green" (value 100.0), one Serie (Keyexpression) "red" (value: $V{state_1}>1?0:new Float(($V{state_1}*100)/$V{til_1}) ).
            <pieChart>
            <chart isShowLegend="false">
                <reportElement x="293" y="0" width="30" height="30" uuid="8369e35a-d6d6-4e0d-aa6e-fef7a118ecce"/>
                <chartTitle/>
                <chartSubtitle/>
                <chartLegend/>
            </chart>
            <pieDataset>
                <pieSeries>
                    <keyExpression><![CDATA["green"]]></keyExpression>
                    <valueExpression><![CDATA[100.0]]></valueExpression>
                    <labelExpression><![CDATA[null]]></labelExpression>
                </pieSeries>
                <pieSeries>
                    <keyExpression><![CDATA["red"]]></keyExpression>
                    <valueExpression><![CDATA[$V{state_1}>1?0:new Float(($V{state_1}*100)/$V{til_1})]]></valueExpression>
                    <labelExpression><![CDATA[null]]></labelExpression>
                </pieSeries>
            </pieDataset>
            <piePlot isShowLabels="false">
                <plot>
                    <seriesColor seriesOrder="0" color="#99FF99"/>
                    <seriesColor seriesOrder="1" color="#CC0000"/>
                </plot>
                <itemLabel/>
            </piePlot>
        </pieChart>

Actual result (including the Problem):
However, when I run the report the calculation for "red" seams to be correct, the Chart output-image does not - link to image attached below.
(50%red instead of 100% and 33,3%red instead of 50%)
Image:

Actual Render-Output of code

Somebody knows where my mistake/how to get the right percentage in Pie Chart and -if possible- a short explanation why does jasper draw wrong chart-slices? Because of the two Series?

1

1 Answers

0
votes

I believe that your problem is: the chart doesn't know what percentage is.

Actually, when you say to it "print serias A as 100" and "print series B as 50" it's going to assume 100% (the total, the full chart) is A + B, which is 150. Then, your series B will show as 33.3% of your total.

So basically, you will need to manually work out your "proportions". For example:

If you have "red" as $V{state_1} > 1 ? 0 : (new Float($V{state_1})/$V{til_1})*100, you can use your "green" as 100 - ($V{state_1} > 1 ? 0 : (new Float($V{state_1})/$V{til_1})*100).