Search code examples
jasper-reportscrosstabtext-rotation

Rotation of Text in Crosstab in Jasper Reports 4.5.0


For reasons too complicated to go into, I have to deploy a new report onto an existing JasperReports Server 4.5.0 installation. It cannot be upgraded. I figured that it would be easiest to use iReport 4.5.0 to ensure compatibility with the Server. Am I mistaken? Would it be better to use a newer version, or to switch to Jaspersoft Studio, or something else?

The report involves a crosstab with many columns. In order to get them all to fit on one standard landscape page, I need to change the rotation of the column headers to vertical. The data inside the cells themselves is very short. I couldn't find an option in iReport to change the rotation of the text in the header, so I changed the XML from:

                <crosstabColumnHeader>
                    <cellContents backcolor="#F0F8FF" mode="Opaque">
                        <box>
                            <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        </box>
                        <textField>
                            <reportElement style="Crosstab Data Text" x="0" y="0" width="50" height="30"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$V{ACTION_DESC}]]></textFieldExpression>
                        </textField>
                    </cellContents>
                </crosstabColumnHeader>

To:

                <crosstabColumnHeader>
                    <cellContents backcolor="#F0F8FF" mode="Opaque">
                        <box>
                            <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        </box>
                        <textField>
                            <reportElement style="Crosstab Data Text" x="0" y="0" width="50" height="30"/>
                            <textElement rotation="Left"/>
                            <textFieldExpression><![CDATA[$V{ACTION_DESC}]]></textFieldExpression>
                        </textField>
                    </cellContents>
                </crosstabColumnHeader>

(In case you don't see it, I added a rotation="Left" to the textElement.)

It doesn't seem to have any effect on the preview, whether I'm previewing to HTML or PDF. I have seen others referring to text rotation in versions even older than mine, so I didn't think that it's unsupported in 4.5.0. Again, am I mistaken?


Solution

  • Is it possible to use JaspersoftStudio (JSS) instead of iReport 4.5.0?

    Yes, for designing and testing templates locally. You can use compatibility mode to save template in format of JasperReports 4.5.0 version.

    But I'm not sure that the integration with old versions of JasperReports Server will be work ok at new versions of JSS.

    Does crosstab support vertical rotated text (at header, for example)?

    Yes, definitely. Rotation is supported by textField element, it is not the feature of crosstab.

    The iReport has the ability to change rotation of text. You can find property Rotation at Text properties block.

    The property for changing text orientation

    The cause of issue you faced is that the size of textField is not enough for showing text. For example if we have textField with default horizontal text with its height too small for showing the text the rendered result will be empty.

    You should just increase the height of textField to solve issue.


    Notes

    More details how to enable compatibility mode at JSS you can find here and here