I'm trying to do an iReport chart with this table
name|totalcalls|handled|abandoned|rejected
customerservice|300|100|100|100
itsupport|500|300|100|100
The idea is that there should be 2 charts in this case, that was easily solved by putting the chart into the details row.
But I cannot figure out how to make iReport treat the 3 last columns (handled, abandoned, rejected) as different series.
Ideally I want to do a stacked barchart that looks like this:
customerservice|-100-|-100-|-100-
itsupport|---300---|-100-|100
I have no clue how to make this work.
To achieve this you can use a stacked bar chart. Open iReport and drag and drop the chart element from the palette to the report designer. In the wizard select Stacked Bar, then click Finish.
Right click on the chart and select Chart Data > Details:
- click Add, enter Series Expression:
"Handled"
, Category Expression: $F{name}
, Value Expression: $F{handled}
, click Ok
- Add, Series Expression:
"Abandoned"
, Category Expression: $F{name}
, Value Expression: $F{abandoned}
, Ok
- Add, Series Expression:
"Rejected"
, Category Expression: $F{name}
, Value Expression: $F{rejected}
, Ok
Then click Close. Now select the chart object in the report designer and change in the properties panel Orientation to horizontal.
I put the chart into the summary band holding both rows of data in a single chart. You can apply the same settings for the chart being configured in the detail band for a similar output if required.
I also attach the JRXML for further reference:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report7" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="42d0d6ab-85f6-496b-8e61-c3d7588cfd8e">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
<![CDATA[select 'customerservice' as name, 300 as totalcalls, 100 as handled, 100 as abandoned, 100 as rejected
union select 'itsupport', 500, 300, 100, 100]]>
</queryString>
<field name="name" class="java.lang.String"/>
<field name="totalcalls" class="java.lang.Long"/>
<field name="handled" class="java.lang.Long"/>
<field name="abandoned" class="java.lang.Long"/>
<field name="rejected" class="java.lang.Long"/>
<summary>
<band height="92">
<stackedBarChart>
<chart>
<reportElement uuid="f0bfeda6-003e-40c0-8d75-0c61bc620978" x="0" y="0" width="555" height="92"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<categoryDataset>
<categorySeries>
<seriesExpression><![CDATA["Handled"]]></seriesExpression>
<categoryExpression><![CDATA[$F{name}]]></categoryExpression>
<valueExpression><![CDATA[$F{handled}]]></valueExpression>
</categorySeries>
<categorySeries>
<seriesExpression><![CDATA["Abandoned"]]></seriesExpression>
<categoryExpression><![CDATA[$F{name}]]></categoryExpression>
<valueExpression><![CDATA[$F{abandoned}]]></valueExpression>
</categorySeries>
<categorySeries>
<seriesExpression><![CDATA["Rejected"]]></seriesExpression>
<categoryExpression><![CDATA[$F{name}]]></categoryExpression>
<valueExpression><![CDATA[$F{rejected}]]></valueExpression>
</categorySeries>
</categoryDataset>
<barPlot>
<plot orientation="Horizontal"/>
<itemLabel/>
</barPlot>
</stackedBarChart>
</band>
</summary>
</jasperReport>