Search code examples
jasper-reports

Jasper Reports: chart based on two columns


I am designing a report with a chart based on fields of the data set. This is the content of the dataset:

enter image description here

I want to add a bars chart with one bar for each entry in the dataset, so I added the following chart code:

<groupFooter>
            <band height="249">
                <bar3DChart>
                    <chart>
                        <reportElement x="10" y="20" width="540" height="200" uuid="532522d1-b004-47b7-9e2a-ff12ab88c7ed"/>
                        <chartTitle/>
                        <chartSubtitle/>
                        <chartLegend/>
                    </chart>
                    <categoryDataset>
                        <dataset resetType="Group" resetGroup="indicador"/>
                        <categorySeries>
                            <seriesExpression><![CDATA[$F{fecha}]]></seriesExpression>
                            <categoryExpression><![CDATA[0]]></categoryExpression>
                            <valueExpression><![CDATA[$F{valor}]]></valueExpression>
                        </categorySeries>
                    </categoryDataset>
                    <bar3DPlot>
                        <plot/>
                        <itemLabel/>
                        <categoryAxisFormat>
                            <axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/>
                        </categoryAxisFormat>
                        <valueAxisFormat>
                            <axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/>
                        </valueAxisFormat>
                    </bar3DPlot>
                </bar3DChart>
            </band>
        </groupFooter>

The problem is that field date is no unique, so the chart doesn't depict the table. I want to set the tag seriesExpression to the combination of fields date and division, because such combination is unique.

How can I do it? I tried putting both fields in the same seriesExpression, but I got an error.

EDIT

I tried putting together both fields: <seriesExpression><![CDATA[$F{fecha}$F{division}]]></seriesExpression>, but I got this errors:

enter image description here


Solution

  • seriesexpression must be an Expression, so if Fecha is a Date something like

    <seriesExpression><![CDATA[new SimpleDateFormat("dd/MM/yyyy").format($F{fecha})+" "+$F{division}]]></seriesExpression>