Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chart repeats many times

I have generated a report (with JasperReport). My problem that the chart repeats, I have one chart and the report contains 22 pages! What is the problem?

This is my report:

<?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="report2" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<subDataset name="New Dataset 1">
    <parameter name="SQL" class="java.lang.String"/>
    <parameter name="Titre" class="java.lang.String">
        <defaultValueExpression><![CDATA[]]></defaultValueExpression>
    </parameter>
    <queryString>
        <![CDATA[$P!{SQL}]]>
    </queryString>
    <field name="nb" class="java.lang.Long"/>
    <field name="champ1" class="java.lang.String"/>
    <field name="champ2" class="java.lang.String"/>
</subDataset>
<parameter name="SQL" class="java.lang.String">
    <defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<parameter name="Titre" class="java.lang.String"/>
<queryString>
    <![CDATA[select id from jiraissue]]>
</queryString>
<field name="id" class="java.math.BigDecimal"/>
<background>
    <band splitType="Stretch"/>
</background>
<title>
    <band height="46" splitType="Stretch">
        <textField>
            <reportElement x="89" y="15" width="180" height="20"/>
            <textElement/>
            <textFieldExpression class="java.lang.String"><![CDATA[$P{Titre}]]></textFieldExpression>
        </textField>
    </band>
</title>
<pageHeader>
    <band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
    <band height="13" splitType="Stretch"/>
</columnHeader>
<detail>
    <band height="185" splitType="Stretch">
        <stackedBar3DChart>
            <chart>
                <reportElement x="57" y="16" width="420" height="165"/>
                <chartTitle/>
                <chartSubtitle/>
                <chartLegend/>
            </chart>
            <categoryDataset>
                <dataset>
                    <datasetRun subDataset="New Dataset 1">
                        <datasetParameter name="SQL">
                            <datasetParameterExpression><![CDATA[$P{SQL}]]></datasetParameterExpression>
                        </datasetParameter>
                        <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                    </datasetRun>
                </dataset>
                <categorySeries>
                    <seriesExpression><![CDATA[$F{champ2}]]></seriesExpression>
                    <categoryExpression><![CDATA[$F{champ1}]]></categoryExpression>
                    <valueExpression><![CDATA[$F{nb}]]></valueExpression>
                </categorySeries>
            </categoryDataset>
            <bar3DPlot>
                <plot/>
                <itemLabel color="#000000" backgroundColor="#FFFFFF"/>
                <categoryAxisFormat>
                    <axisFormat>
                        <labelFont/>
                        <tickLabelFont/>
                    </axisFormat>
                </categoryAxisFormat>
                <valueAxisFormat>
                    <axisFormat>
                        <labelFont/>
                        <tickLabelFont/>
                    </axisFormat>
                </valueAxisFormat>
            </bar3DPlot>
        </stackedBar3DChart>
    </band>
</detail>
<columnFooter>
    <band height="24" splitType="Stretch"/>
</columnFooter>
<pageFooter>
    <band height="20" splitType="Stretch"/>
</pageFooter>
<summary>
    <band height="22" splitType="Stretch"/>
</summary>

Update I have solved the problem by moving the chart to the summary part :)

like image 836
rym Avatar asked Jul 08 '11 09:07

rym


1 Answers

In Jasper Report, everything you place in the detail band is repeated number of times it appears in the source.

If you want to show anything (not only chart) just once, avoid the detail band. For example, you can place it in the summary section.

Update: As others pointed, I have extended my answer a little bit.

like image 177
Osmani Avatar answered Sep 28 '22 11:09

Osmani