0
votes

Say I have multiple detail bands containing pie charts. Each pie chart's JRXML looks like:

<pieDataset>
    <keyExpression><![CDATA[$F{PieSlice}.label]]></keyExpression>
    <valueExpression><![CDATA[$F{PieSlice}.value]]></valueExpression>
</pieDataset>

And then I use a JRBeanArrayDataSource to fill those pie charts:

public class PieSlice
{
    private String label;
    private Double value;

    public PieSlice()
    {
        this("", -1);
    }

    public PieSlice(String lbl, Double val)
    {
        setLabel(lbl);
        setValue(val);
    }

    public String getLabel()
    {
        return label;
    }

    public String getValue()
    {
        return value;
    }
}

public class PieSliceFactory
{
    private static PieSlice[] slices = 
    {
        new PieSlice("Fizz", 75.0),
        new PieSlice("Buzz", 25.0);
    };

    public static PieSlice[] getSlices()
    {
        return ArrayList.asList(slices);
    }
}

JasperReport jasperReport = JasperFillManager.fillReport(jasperDesign, new JRBeanArrayDataSource(PieSliceFactory.getSlices()));

Then how do I specify which data from the bean array gets "routed" to the correct pie chart? What if I only want the "Fizz" pie slice to go to pie chart X inside detail band A, but I want the "Buzz" slice to fill pie chart Y inside detail band B?

Is there a way to use IDs in the expressions or CDATA? There has to be a way to make specify which bands/elements data gets mapped to. The expression $F{ClassName}.property just seems too generic. Thanks in advance!

1

1 Answers

0
votes

If your result set has 3 rows, then your detail band will repeat 3 times. If you put a pie chart in the detail band, then you'll get 3 pie charts.

Your code above uses misleading names because you'll have one PieSlice in each row. So those PieSlices can't really be pie slices. Well.. of course they CAN... but each pie will have a single slice. It won't be useful.

It sounds like you need to put the pie chart into the title or summary band. Then you'll have the full data set to work with. You can have each of the pie slice labels and values represented in the chart.