Planet Jaspersoft

Filter by tags:

December 15, 2015

Hi Folks,

 (Theory will update here later tomorrow or so, meanwhile use the JRXML to view the output)

Data bases used : 
1) MySQL , sakila db
2) PostgreSQL foodmart db.

Sample output



Copy paste this code in your JRXML source code and observe the "Dataset1" data source parameters and connections as well the main report query and its connection.

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.1.0.final using JasperReports Library version 6.1.0  -->
<!-- 2015-12-16T00:19:39 -->
<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="MyFirst Report" pageWidth="610" pageHeight="842" columnWidth="570" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="295ab2d1-1932-4c33-823a-b088e233383f">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sakila - MySQL"/>
    <property name="com.jaspersoft.studio.unit." value="pixel"/>
    <property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
    <style name="Table_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
            <topPen lineWidth="0.5" lineColor="#000000"/>
            <leftPen lineWidth="0.5" lineColor="#000000"/>
            <bottomPen lineWidth="0.5" lineColor="#000000"/>
            <rightPen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="Table_CH" mode="Opaque" backcolor="#BFE1FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
            <topPen lineWidth="0.5" lineColor="#000000"/>
            <leftPen lineWidth="0.5" lineColor="#000000"/>
            <bottomPen lineWidth="0.5" lineColor="#000000"/>
            <rightPen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
            <topPen lineWidth="0.5" lineColor="#000000"/>
            <leftPen lineWidth="0.5" lineColor="#000000"/>
            <bottomPen lineWidth="0.5" lineColor="#000000"/>
            <rightPen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="Table 1_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
            <topPen lineWidth="0.5" lineColor="#000000"/>
            <leftPen lineWidth="0.5" lineColor="#000000"/>
            <bottomPen lineWidth="0.5" lineColor="#000000"/>
            <rightPen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="Table 1_CH" mode="Opaque" backcolor="#BFE1FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
            <topPen lineWidth="0.5" lineColor="#000000"/>
            <leftPen lineWidth="0.5" lineColor="#000000"/>
            <bottomPen lineWidth="0.5" lineColor="#000000"/>
            <rightPen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="Table 1_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
            <topPen lineWidth="0.5" lineColor="#000000"/>
            <leftPen lineWidth="0.5" lineColor="#000000"/>
            <bottomPen lineWidth="0.5" lineColor="#000000"/>
            <rightPen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <subDataset name="Dataset1" uuid="d0d375a4-ddad-4353-8013-29dd8f924ee6">
        <property name="com.jaspersoft.studio.data.defaultdataadapter" value="foodmart"/>
        <queryString>
            <![CDATA[select * from customer  limit 10]]>
        </queryString>
        <field name="customer_id" class="java.lang.Integer"/>
        <field name="account_num" class="java.lang.Long"/>
        <field name="lname" class="java.lang.String"/>
        <field name="fname" class="java.lang.String"/>
    </subDataset>
    <parameter name="Parameter1" class="java.sql.Connection">
        <defaultValueExpression><![CDATA[java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/foodmart","postgres","postgres")]]></defaultValueExpression>
    </parameter>
    <queryString>
        <![CDATA[select * from actor limit 5]]>
    </queryString>
    <field name="actor_id" class="java.lang.Integer">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <field name="first_name" class="java.lang.String">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <field name="last_name" class="java.lang.String">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <field name="last_update" class="java.sql.Timestamp">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <title>
        <band height="30">
            <textField>
                <reportElement mode="Opaque" x="0" y="0" width="555" height="30" forecolor="#FFFFFF" backcolor="#140AA6" uuid="b7e23fc2-6761-4e4c-9d81-3ed743736088"/>
                <box>
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Left" verticalAlignment="Middle">
                    <font size="12" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA["Sample Data from MySQL (actors Table from Sakila DB) - Usal Grid Data"]]></textFieldExpression>
            </textField>
        </band>
    </title>
    <columnHeader>
        <band height="30">
            <staticText>
                <reportElement x="0" y="0" width="141" height="30" uuid="3eb6afeb-84ce-43ec-89bb-12deef6ea8cc"/>
                <box>
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[Actor ID]]></text>
            </staticText>
            <staticText>
                <reportElement x="141" y="0" width="138" height="30" uuid="0447724f-01b9-467b-b63d-1cc3b32f21d9"/>
                <box>
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[First Name]]></text>
            </staticText>
            <staticText>
                <reportElement x="279" y="0" width="138" height="30" uuid="b6cb62b5-ca07-4059-b336-0d7bbc9c144d"/>
                <box>
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[Last Name]]></text>
            </staticText>
            <staticText>
                <reportElement x="417" y="0" width="138" height="30" uuid="f8e0ace8-5bda-4a21-8b6a-59a5ced2ab28"/>
                <box>
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[Last Update]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="30">
            <textField>
                <reportElement x="0" y="0" width="141" height="30" uuid="1cc25a45-7e39-45d5-ba5a-d0fd7002f754"/>
                <box>
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <textFieldExpression><![CDATA[$F{actor_id}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="141" y="0" width="138" height="30" uuid="dac36d6a-dd6e-4733-b8a6-377fd5bceb81"/>
                <box>
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <textFieldExpression><![CDATA[$F{first_name}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="279" y="0" width="138" height="30" uuid="02859075-ae5d-4c2e-8a83-09fe29abb34c"/>
                <box>
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <textFieldExpression><![CDATA[$F{last_name}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="417" y="0" width="138" height="30" uuid="bffb90ed-fc35-41b4-a39b-fe28af23e307"/>
                <box>
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <textFieldExpression><![CDATA[$F{last_update}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <summary>
        <band height="100" splitType="Stretch">
            <componentElement>
                <reportElement x="0" y="40" width="560" height="60" uuid="fdcac2e9-0944-42ed-bf44-7b73595775bf"/>
                <jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
                    <datasetRun subDataset="Dataset1" uuid="70bb99c8-d50e-43df-a7da-9c4ad8b50ac8">
                        <datasetParameter name="REPORT_CONNECTION">
                            <datasetParameterExpression><![CDATA[java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/foodmart","postgres","postgres")]]></datasetParameterExpression>
                        </datasetParameter>
                    </datasetRun>
                    <jr:column width="130" uuid="b05aaed5-3d79-4bde-877e-c27574732176">
                        <jr:columnHeader style="Table 1_CH" height="30">
                            <staticText>
                                <reportElement x="0" y="0" width="130" height="30" uuid="b06296b3-25a3-4ab5-8e07-8bb87252e358"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font size="12" isBold="true"/>
                                </textElement>
                                <text><![CDATA[Customer ID]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="Table 1_TD" height="30">
                            <textField>
                                <reportElement x="0" y="0" width="130" height="30" uuid="491cf206-6da6-4935-9583-1bcd01b054ed"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                                <textFieldExpression><![CDATA[$F{customer_id}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="130" uuid="0e829c3e-9ce9-413c-b7f7-5c422600915c">
                        <jr:columnHeader style="Table 1_CH" height="30">
                            <staticText>
                                <reportElement x="0" y="0" width="130" height="30" uuid="e562ec15-d83d-4d24-ad05-8f9089e00417"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font size="12" isBold="true"/>
                                </textElement>
                                <text><![CDATA[Account Number]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="Table 1_TD" height="30">
                            <textField>
                                <reportElement x="0" y="0" width="130" height="30" uuid="9f092a95-c914-4cb3-833a-0533262218e8"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                                <textFieldExpression><![CDATA[$F{account_num}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="160" uuid="d6835cd4-c0c8-4572-9c1f-69757dae0058">
                        <jr:columnHeader style="Table 1_CH" height="30">
                            <staticText>
                                <reportElement x="0" y="0" width="160" height="30" uuid="9740787e-699e-4bf6-afdb-8a42a9be401f"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font size="12" isBold="true"/>
                                </textElement>
                                <text><![CDATA[Last Name]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="Table 1_TD" height="30">
                            <textField>
                                <reportElement x="0" y="0" width="160" height="30" uuid="aa773812-1211-458d-9db9-d6a2158b15d5"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                                <textFieldExpression><![CDATA[$F{lname}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="140" uuid="66e70e1b-089b-4f37-abca-177c15501335">
                        <jr:columnHeader style="Table 1_CH" height="30">
                            <staticText>
                                <reportElement x="0" y="0" width="140" height="30" uuid="6ad992bd-f73d-4d76-a641-e2b5c020f178"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font size="12" isBold="true"/>
                                </textElement>
                                <text><![CDATA[First Name]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="Table 1_TD" height="30">
                            <textField>
                                <reportElement x="0" y="0" width="140" height="30" uuid="490c9352-0017-47ba-a35d-03264e28682c"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                                <textFieldExpression><![CDATA[$F{fname}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
            <textField>
                <reportElement mode="Opaque" x="0" y="15" width="560" height="25" forecolor="#FFFFFF" backcolor="#140AA6" uuid="e04d653c-7197-4ffe-8078-c70d101190b4">
                    <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                </reportElement>
                <box>
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Left" verticalAlignment="Middle">
                    <font size="12" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA["Sample Data from PostgreSQL(customers table from foodmart DB) - Table Component"]]></textFieldExpression>
            </textField>
        </band>
    </summary>
</jasperReport>


How to get the same output in the Jasper Server ? 
By creating Virtual Data source defined in Jasper Server and pointing out the report to use this data source.

NOTE : Virtual Data source concept is an enterprise feature in Jaspersoft BI. 

References : 
http://community.jaspersoft.com/wiki/multiple-datasources-ireport-lists-tables-and-subreports
http://community.jaspersoft.com/wiki/connecting-jasperreports-server-your-database



December 15, 2015

December 8, 2015


This post will give you the inputs on how to get the non rounded(exact values) after decimal points for Double or Big Decimal types in Jasper Reports/(Java).

There are situations in reporting to display the exact values after decimal point for some purpose.

For example : 
4.53455 should get printed as 4.53
0.234 should get printed as 0.23,
0.057 should get printed as 0.05 (but not 0.06 by rounding)
0.389 should get printed as 0.38 (but not 0.39 by rounding)

The above implementation in  JAVA is pretty easy but in jasper it would be a tricky as shown in below examples.

Examples : 
new BigDecimal(new Double(0.05592538471251264)).setScale(1, RoundingMode.DOWN)

new BigDecimal(new Double(1.9596988841721044)).setScale(1, RoundingMode.DOWN)

new BigDecimal(new Double(91.0)).setScale(1, RoundingMode.DOWN)

new BigDecimal(new Double(.0)).setScale(1, RoundingMode.DOWN)

Sample output : 
 
Sample JRXML :  ( Copy paste the below code in your source in professional studio)

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.0.1.final using JasperReports Library version 6.0.0  -->
<!-- 2015-12-08T13:29:09 -->
<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="Blank_A4_1" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="927e91d9-da47-46ff-b6a9-744c47f3dff0">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <title>
        <band height="298" splitType="Stretch">
            <textField>
                <reportElement mode="Opaque" x="153" y="72" width="180" height="40" backcolor="#BFF2CF" uuid="a39e7410-e811-4545-81b2-94d0239c43ee"/>
                <box rightPadding="10">
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font size="12"/>
                </textElement>
                <textFieldExpression><![CDATA[String.format("%.1f",0.05592538471251264)]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Opaque" x="153" y="122" width="180" height="30" backcolor="#EFDAF7" uuid="69394848-d852-4f9f-b3b3-f644e06608ed"/>
                <box rightPadding="10">
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font size="12"/>
                </textElement>
                <textFieldExpression><![CDATA[new BigDecimal(new Double(0.05592538471251264)).setScale(1, RoundingMode.DOWN)]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Opaque" x="-1" y="122" width="154" height="30" backcolor="#EFDAF7" uuid="4b65ff63-e767-43a4-806e-0b8548175946"/>
                <box rightPadding="10">
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font size="12"/>
                </textElement>
                <textFieldExpression><![CDATA["0.05592538471251264"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Opaque" x="150" y="160" width="183" height="30" backcolor="#EFDAF7" uuid="6595f244-af18-4c15-aa98-95494397055b"/>
                <box rightPadding="10">
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font size="12"/>
                </textElement>
                <textFieldExpression><![CDATA[new BigDecimal(new Double(1.9596988841721044)).setScale(1, RoundingMode.DOWN)]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Opaque" x="-1" y="160" width="151" height="30" backcolor="#EFDAF7" uuid="5088a6a2-d02c-4461-81e5-afeb3d0e667f"/>
                <box rightPadding="10">
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font size="12"/>
                </textElement>
                <textFieldExpression><![CDATA["1.9596988841721044"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Opaque" x="353" y="122" width="180" height="30" backcolor="#EFDAF7" uuid="7b137a50-3266-48e1-b6f6-5d96c706e7aa"/>
                <box rightPadding="10">
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font size="12"/>
                </textElement>
                <textFieldExpression><![CDATA["("+new BigDecimal(new Double(0.05592538471251264)).setScale(1, RoundingMode.DOWN) +"%"+")"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Opaque" x="352" y="161" width="183" height="30" backcolor="#EFDAF7" uuid="eb1c793d-be6b-4140-ab17-403e509b70a2"/>
                <box rightPadding="10">
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font size="12"/>
                </textElement>
                <textFieldExpression><![CDATA["("+new BigDecimal(new Double(1.9596988841721044)).setScale(1, RoundingMode.DOWN)+"%"+")"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Opaque" x="-1" y="203" width="154" height="30" backcolor="#EFDAF7" uuid="2be78c2f-121a-420f-840a-4053ca87699c"/>
                <box rightPadding="10">
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font size="12"/>
                </textElement>
                <textFieldExpression><![CDATA["91.0"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Opaque" x="355" y="204" width="183" height="30" backcolor="#EFDAF7" uuid="365e3fae-e19e-4f49-aa7a-020438455903"/>
                <box rightPadding="10">
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font size="12"/>
                </textElement>
                <textFieldExpression><![CDATA["("+new BigDecimal(new Double(91.0)).setScale(1, RoundingMode.DOWN)+"%"+")"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Opaque" x="153" y="203" width="183" height="30" backcolor="#EFDAF7" uuid="3ffc22a8-ce74-4780-a6ab-af43b9e1b10d"/>
                <box rightPadding="10">
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font size="12"/>
                </textElement>
                <textFieldExpression><![CDATA[new BigDecimal(new Double(91.0)).setScale(1, RoundingMode.DOWN)]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Opaque" x="152" y="248" width="183" height="30" backcolor="#EFDAF7" uuid="c7450588-2e81-44a8-bff9-c96a7fa645dd"/>
                <box rightPadding="10">
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font size="12"/>
                </textElement>
                <textFieldExpression><![CDATA[new BigDecimal(new Double(.0)).setScale(1, RoundingMode.DOWN)]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Opaque" x="354" y="249" width="183" height="30" backcolor="#EFDAF7" uuid="fb7c9922-230e-475c-afe1-1aa0b675097a"/>
                <box rightPadding="10">
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font size="12"/>
                </textElement>
                <textFieldExpression><![CDATA["("+new BigDecimal(new Double(.0)).setScale(1, RoundingMode.DOWN)+"%"+")"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Opaque" x="-1" y="248" width="153" height="30" backcolor="#EFDAF7" uuid="6d9ccc44-f198-499b-9385-c2d25bd2a46b"/>
                <box rightPadding="10">
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font size="12"/>
                </textElement>
                <textFieldExpression><![CDATA[".0"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Opaque" x="1" y="72" width="151" height="40" backcolor="#BFF2CF" uuid="a5f36874-8b7c-45cd-bd3b-f8cbe33c2418"/>
                <box rightPadding="10">
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font size="12"/>
                </textElement>
                <textFieldExpression><![CDATA["0.05592538471251264"+"\n"+"Using String format"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Opaque" x="353" y="72" width="180" height="40" backcolor="#BFF2CF" uuid="2f2688c8-b600-4acc-a069-7a22fe263ae8"/>
                <box rightPadding="10">
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font size="12"/>
                </textElement>
                <textFieldExpression><![CDATA["("+String.format("%.1f",0.05592538471251264) +"%"+")"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Opaque" x="0" y="21" width="555" height="30" backcolor="#E3E1E3" uuid="c103067c-da2e-4091-b18c-357aebf5e113"/>
                <box>
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="12" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA["Display RoundingMode.DOWN values for Decimal Types in Jasper Reports"]]></textFieldExpression>
            </textField>
        </band>
    </title>
</jasperReport>


References : 
1) http://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html
2) http://docs.oracle.com/javase/7/docs/api/java/math/RoundingMode.html

December 8, 2015

December 7, 2015

Hi Folks,

This post will teach you how to work with 100% horizontal stacked highcharts bar chart in Jasper reports and how to work with Advanced properties of it.

I hope this would help some one in saving their(s) time.

Software used to test this example : 
1) Jasper Design Studio 6.1
2) foodmart database of postgresql
3) Jasper Server 6.0.1 professional & Mozilla firefox web browser.

Sample output of the report : 
I hope you have already knew how to create a new report hence skipping some basic steps and concentrating in explaining core parts.
1) Sample Query Design
SELECT
    occupation,
    state_province,
    SUM(num_cars_owned) cars
FROM customer c
WHERE state_province IN('CA','WA','OR')
GROUP BY
    occupation ,
    state_province
ORDER BY
    occupation,
    state_province

2) Sample output of the query 

3) Drag and drop "StackedPercBar" chart from HTML-5 charts component from Palette section.

4)  Right click on it get the chart properties.
   In chart data section & under configuration tab give below.
Category : $F{occupation} (of java.lang.String type)
Series : $F{state_province} (of java.lang.String type)
Measures : $F{cars} (of java.lang.Integer type)

5) Come back to the chart properties and click on Advanced Properties and click on "Add" button to add below properties.

plotOptions.series.dataLabels.enabled = ture
(Tick the check box) - to enable the values
plotOptions.series.dataLabels.format =" {point.percentage:.0f} % "
(tick the check box) - to get the %'s
plotOptions.series.dataLabels.color = #FF0000
(do not check the tick box) - to get the colors for values

See below image for accuracy 


6) Save the report, publish it the server and have preview. Output should look as shown in first image to this post.

JRXML code : (copy paste the code to get the same copy in your JRXML source , note that it will only work in professional studio or iReport).

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.0.1.final using JasperReports Library version 6.0.0  -->
<!-- 2015-12-07T21:20:57 -->
<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="Blank_A4_1" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="f8b9b5a2-390b-4136-94c7-00c39ec1a61d">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="foodmart"/>
    <property name="ireport.jasperserver.url" value="http://localhost:8080/jasperserver-pro/"/>
    <property name="ireport.jasperserver.user" value="superuser"/>
    <property name="ireport.jasperserver.report.resource" value="/Explore/HTML5BarChart_files/main_jrxml"/>
    <property name="ireport.jasperserver.reportUnit" value="/Explore/HTML5BarChart"/>
    <queryString language="SQL">
        <![CDATA[SELECT
    occupation,
    state_province,
    SUM(num_cars_owned) cars
FROM customer c
WHERE state_province IN('CA','WA','OR')
GROUP BY
    occupation ,
    state_province
ORDER BY
    occupation,
    state_province
]]>
    </queryString>
    <field name="occupation" class="java.lang.String"/>
    <field name="cars" class="java.lang.Long"/>
    <field name="state_province" class="java.lang.String"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <summary>
        <band height="340" splitType="Stretch">
            <componentElement>
                <reportElement x="0" y="0" width="555" height="340" uuid="b2a63a16-5851-438a-af78-98a11b27ddf3"/>
                <hc:chart xmlns:hc="http://jaspersoft.com/highcharts" xsi:schemaLocation="http://jaspersoft.com/highcharts http://jaspersoft.com/schema/highcharts.xsd" type="StackedPercentBar">
                    <hc:chartSetting name="default">
                        <hc:chartProperty name="chart.zoomType">
                            <hc:propertyExpression><![CDATA["xy"]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="credits.enabled">
                            <hc:propertyExpression><![CDATA[false]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="credits.href">
                            <hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="credits.text">
                            <hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="legend.enabled">
                            <hc:propertyExpression><![CDATA[Boolean.FALSE]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="plotOptions.series.allowPointSelect">
                            <hc:propertyExpression><![CDATA[Boolean.TRUE]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="plotOptions.series.connectNulls">
                            <hc:propertyExpression><![CDATA[Boolean.TRUE]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="plotOptions.series.dataLabels.color" value="#FF0000"/>
                        <hc:chartProperty name="plotOptions.series.dataLabels.enabled">
                            <hc:propertyExpression><![CDATA[true]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="plotOptions.series.dataLabels.format">
                            <hc:propertyExpression><![CDATA[" {point.percentage:.0f} % "]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="plotOptions.series.selected">
                            <hc:propertyExpression><![CDATA[Boolean.TRUE]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="plotOptions.series.showCheckBox">
                            <hc:propertyExpression><![CDATA[Boolean.TRUE]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="title.text">
                            <hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="yAxis.title.text">
                            <hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
                        </hc:chartProperty>
                    </hc:chartSetting>
                    <multiAxisData>
                        <multiAxisDataset/>
                        <dataAxis axis="Rows">
                            <axisLevel name="Level1">
                                <labelExpression><![CDATA["Level Label expression"]]></labelExpression>
                                <axisLevelBucket class="java.lang.String">
                                    <bucketExpression><![CDATA[$F{occupation}]]></bucketExpression>
                                </axisLevelBucket>
                            </axisLevel>
                        </dataAxis>
                        <dataAxis axis="Columns">
                            <axisLevel name="state_province">
                                <labelExpression><![CDATA[]]></labelExpression>
                                <axisLevelBucket order="None" class="java.lang.String">
                                    <bucketExpression><![CDATA[$F{state_province}]]></bucketExpression>
                                </axisLevelBucket>
                            </axisLevel>
                        </dataAxis>
                        <multiAxisMeasure name="cars" class="java.lang.Integer" calculation="Nothing">
                            <labelExpression><![CDATA["Measure label expression"]]></labelExpression>
                            <valueExpression><![CDATA[$F{cars}]]></valueExpression>
                        </multiAxisMeasure>
                    </multiAxisData>
                    <hc:series name="cars"/>
                </hc:chart>
            </componentElement>
        </band>
    </summary>
</jasperReport>

Thank you for reading this post.

If you find it useful, please hit the share button to help the community.

Cheers.!
Sadakar Pochampalli


December 7, 2015

Hi folks,
Here is the small workout. Hope you may find it useful.

Requirement is subjected to this post. :-)

Steps : 
1) Right click on the bar chart ( Column vertical bar chart).
2) Click on "Show Advanced Properties"
3) Click on "Add" button to add below 3 properties.
plotOptions.series.dataLabels.enabled = true
NOTE :
# no double quotes for true & check tick mark of Use an expression
# This property enables the data values to show on bar(values would be outside of bar).

plotOptions.series.dataLabels.rotation= new Integer(90) 
NOTE:
# check the tick mark of Use an expression
# This property rotates the data values vertically on bar.

plotOptions.series.dataLabels.y= new Integer(-20) 
NOTE:
# check the tick mark of Use an expression
# This property is used to give the distance to the value vertically from the bar top. 

Sample output : 



How to in JRXML ?

  JRXML Code : 
(It works on foodmart database of Jasper postgresql & works with professional jasper studio only).

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.0.1.final using JasperReports Library version 6.0.0  -->
<!-- 2015-12-07T20:52:05 -->
<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="Blank_A4" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="82e08b7f-0e4f-4aae-8514-6cdd45c368bf">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="foodmart - postgres"/>
    <property name="ireport.jasperserver.url" value="http://localhost:8080/jasperserver-pro/"/>
    <property name="ireport.jasperserver.user" value="superuser"/>
    <property name="ireport.jasperserver.report.resource" value="/Explore/HTML5BarChart2_files/main_jrxml"/>
    <property name="ireport.jasperserver.reportUnit" value="/Explore/HTML5BarChart2"/>
    <queryString language="SQL">
        <![CDATA[SELECT occupation,state_province, SUM(num_cars_owned) cars FROM customer c GROUP BY occupation ,state_province ORDER BY occupation ,state_province ]]>
    </queryString>
    <field name="occupation" class="java.lang.String"/>
    <field name="state_province" class="java.lang.String"/>
    <field name="cars" class="java.lang.Long"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <summary>
        <band height="343" splitType="Stretch">
            <componentElement>
                <reportElement x="0" y="0" width="555" height="343" uuid="a5884ec2-1cf0-447b-b1dc-ba58f5056eba"/>
                <hc:chart xmlns:hc="http://jaspersoft.com/highcharts" xsi:schemaLocation="http://jaspersoft.com/highcharts http://jaspersoft.com/schema/highcharts.xsd" type="Column">
                    <hc:chartSetting name="default">
                        <hc:chartProperty name="_showMeasureNameOnValueAxis">
                            <hc:propertyExpression><![CDATA[Boolean.TRUE]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="chart.zoomType">
                            <hc:propertyExpression><![CDATA["xy"]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="credits.enabled">
                            <hc:propertyExpression><![CDATA[false]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="credits.href">
                            <hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="credits.text">
                            <hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="plotOptions.series.dataLabels.enabled">
                            <hc:propertyExpression><![CDATA[true]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="plotOptions.series.dataLabels.rotation">
                            <hc:propertyExpression><![CDATA[new Integer(90)]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="plotOptions.series.dataLabels.y">
                            <hc:propertyExpression><![CDATA[new Integer(-20)]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="title.text">
                            <hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="yAxis.title.text">
                            <hc:propertyExpression><![CDATA["Measure label expression"]]></hc:propertyExpression>
                        </hc:chartProperty>
                    </hc:chartSetting>
                    <multiAxisData>
                        <multiAxisDataset/>
                        <dataAxis axis="Rows">
                            <axisLevel name="Level1">
                                <labelExpression><![CDATA["Level Label expression"]]></labelExpression>
                                <axisLevelBucket class="java.lang.String">
                                    <bucketExpression><![CDATA[$F{occupation}]]></bucketExpression>
                                </axisLevelBucket>
                            </axisLevel>
                        </dataAxis>
                        <dataAxis axis="Columns"/>
                        <multiAxisMeasure name="Measure1" class="java.lang.Integer" calculation="Nothing">
                            <labelExpression><![CDATA["Measure label expression"]]></labelExpression>
                            <valueExpression><![CDATA[$F{cars}]]></valueExpression>
                        </multiAxisMeasure>
                    </multiAxisData>
                    <hc:series name="Measure1"/>
                </hc:chart>
            </componentElement>
        </band>
    </summary>
</jasperReport>


References : 
1) http://api.highcharts.com/highcharts#plotOptions.series.dataLabels 
2) http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/plotoptions/series-datalabels-align-left/ 
3) http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/plotoptions/series-datalabels-rotation/
4) http://community.jaspersoft.com/wiki/advanced-formatting-new-html5-charts

December 7, 2015

December 4, 2015

Hi,

Problem Statement : 
In some requirements, we need to print larger text value of a field in the reports & we do it dragging to the report console as usual but will stop with an error saying
java.lang.ArrayIndexOutOfBoundsException: 0 with out further error message. 

Solution : 
Its because  of the no compatability conversion understanding of SQL and Java to handle the spaces or tab spaces in the string value. 

We can overcome it at SQL level by using "replace" funciton. 

Lets say, the column name could be ProjectDescription in the SQL code. 
 & Lets assume one of the values for it is "This is a reporting project, this report is used to find the maximum of something and etc ..........up to some 3000 characters description". 

In SQL code use "replace" function to the field as shown below. 

Syntax : 
" replace([column_name], CHR(9))  " 
Example : 
replace(ProjectDescription,CHR(9))

 NOTE :
# This example is Oracle SQL specific, if you are working on other DBMS soft wares, find the similar replace function it and test. 

Similar issues can be found at below threads from community
1) http://community.jaspersoft.com/jasperreports-library/issues/4631
2) http://community.jaspersoft.com/questions/803333/tabs-text-mess-pdf-output
3) http://community.jaspersoft.com/questions/532690/using-tab-escape-sequence-text-field-expression

I hope this helps some one. !

Cheers..!
:-) :-) 
 

December 4, 2015

Hi Folks,
Here is a latest work around for displaying "All" when passing nothing from "Multi select parameter" in Jasper reports.

Concept :
Display the selected values of multi select parameter on the report.
Lets say if you select "USA","Mexico" from the multi select drop down, your report should display USA,Mexico
and if you select nothing in the drop down it should display All on the report instead of all the countries.


Solution :
Find the empty collection length, if the lenght is <=2 display "All" and if the lengh is > 2 display the selected values.
•    Create a Parameter as collection (coming from clarity)
            param_country (java.util.Collection)
•    Create another parameter which will calculate the length of multi select param
            param_country_length (java.lang.String)
        * Under default value expression, write below expression
                     $P{param_country}.toString().length()
•    Your Query for report should be as follows.

SELECT
        nvl(to_char(WM_CONCAT(replace(replace(Country_Field, '['), ']'))), 'All') cf
FROM customers
WHERE
    (
            ($P{param_country_length}) > 2 and $X{IN,lookup_code,param_inv_type}
            OR
            ($P{param_country_length}) < = 2
    )

  
    
* NOTE :

# "All" should not be a value from the dropdown.
# All should be handled from SQL code.
# Query used is Oracle SQL 11g (+) specific. Functions used in SQL code may not work in lesser versions.
# Tested the report using Jasper Design Studio 6.x Professional.
# On report to display the countries use filed instead of parameter name.
   i.e., $F{Country_Field} instead of $P{param_country}
# Do all this in a sub report and call it in main report because you can not handle it in main report.
# This may not work when you select "All" option available in the multi select drop down. ( Not tested).
# This is one of the ways, we have implemented in a report. I believe there could be other ways to solve the same.

Thanks,
Sadakar Pochampalli
Open Source BI specialist. 






  

December 4, 2015

December 1, 2015

Hi Folks,

Some times, small things in any technology becomes harder to find and consumes time to check whether it is possible or not or how to implement it.

Today, I have come across a small requirement that is to print half colored text taken in a "Static Text Field" or "Text Filed" in Jasper reports.

Thanks to the folks who looked into it very quickly & solved it out.

I would like to share it the community on how to do this with above two elements on behalf of my folks findings. Hope you may find it useful.

Problem Statement & Solution can be understood from below image. 


Software used to Test this example : 
1) Jasper Design Studio 6.1 professional / you can use CE Studio also.
2) Empty Data source.
3) Jasper Server is not taken to test it.

Steps :
1) Create a JRXML report as usual with no need of any data source and in the report properties select when  no data type= All sections, No detail.

2)
# Drag and drop "Static Text" element from Palette to "Title" band and adjust height and width.
# Give below expression in it.
# Select the "Static Text" and go to its properties and Markup = html

<span style="color: red;">This is red colored text</span> <br>
<span style="color:green;">This is green colored Text</span>  <br>
<span> These texts are in single Static Text Field and there in single lines</span>


NOTE : As Markup=html the <br> will work to print the text in new line. 


3) Now,
#  Drag and drop "Text" element from Palette to "Title" below to above(step-2) element.
# Give below expression in it.
# Select "Text" element and go to its properties and give "Markup=styled"

"<style forecolor='#F71C19'> Hi,I am red in color..!</style>"+"\n"+
"<style forecolor='#15D636'> Hi,I am green in color..!</style>" + "\n"+
"<style forecolor='#000000'>Hello,we both are in single Text Filed and in separate lines..!</style>"


NOTE : As the lines of code is enclosed in double quotes the sentences inside them work as "JAVA" language strings and in Java we use "\n" to separate the lines. 

NOTE : Read is used to high light the code section in the article. 

4) Save the report and preview

5) Sample output will look like as shown in image in the beginning.

References : 
1) http://jasperreports.sourceforge.net/sample.reference/markup/

2) Crystal to Jasper conversion.
( In crystal it is very easy, one can select the amount of text placed in element with mouse cursor and apply the color)   


JRXML code
 <?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.0.1.final using JasperReports Library version 6.0.0  -->
<!-- 2015-12-02T01:06:10 -->
<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="Upload from server UI" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="da3cf4d1-d5ae-4e7d-acf6-5a6900abf344">
    <property name="ireport.jasperserver.url" value="http://172.16.0.28:8081/ppmreports/"/>
    <property name="ireport.jasperserver.user" value="superuser"/>
    <property name="ireport.jasperserver.report.resource" value="/organizations/training/Examples/PublishfromStudio2_files/main_jrxml"/>
    <property name="ireport.jasperserver.reportUnit" value="/organizations/training/Examples/PublishfromStudio2"/>
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
    <queryString language="SQL">
        <![CDATA[]]>
    </queryString>
    <title>
        <band height="285" splitType="Stretch">
            <staticText>
                <reportElement x="0" y="0" width="555" height="140" uuid="d8016ec9-0d13-4c4f-8f2f-6ee73349d052"/>
                <box>
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle" markup="html">
                    <font size="16" isBold="true"/>
                </textElement>
                <text><![CDATA[<span style="color: red;">This is red colored text</span> <br>
<span style="color:green;">This is green colored Text</span>  <br>
<span> These texts are in single Static Text Field and there in single lines</span>]]></text>
            </staticText>
            <textField>
                <reportElement x="0" y="145" width="555" height="134" uuid="26119933-1eb9-49bb-923b-190f735f9a59"/>
                <box>
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle" markup="styled">
                    <font size="16" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA["<style forecolor='#F71C19'> Hi,I am red in color..!</style>"+"\n"+
"<style forecolor='#15D636'> Hi,I am green in color..!</style>" + "\n"+
"<style forecolor='#000000'>Hello,we both are in single Text Field and in separate lines..!</style>"]]></textFieldExpression>
            </textField>
        </band>
    </title>
    <columnHeader>
        <band height="45" splitType="Stretch"/>
    </columnHeader>
    <detail>
        <band height="163" splitType="Stretch"/>
    </detail>
</jasperReport>


 Did you find it useful ? Please click on share to help the community. 

Cheers.!
Thank you for landing on this page.  







December 1, 2015

November 10, 2015

Hi,
This tip is useful when exporting the report to excel with negative values.

1) Select the text field that is dragged to the designer.
   (Note that the type of this field is java.math.BigDecimal)

2) Click on it and go to the properties and apply below pattern.
    #,##0.00;(#,##0.00)

3) In above pattern the first piece is applied when the BigDecimal is non-negative and second is applied when the BigDecimal is negative. 

4) This type of pattern is useful when exporting the report to Excel. 
     i.e., Differentiate negative values surrounded by parenthesis.

NOTE : In excel export if you want to get the red color then give the pattern like below.
[Red]#,##0.00;[Red](#,##0.00)

The above pattern will display Red on the Jasper report viewer but when export the report it will give you red colored decimal with the pattern applied. 
  

http://community.jaspersoft.com/questions/525396/pattern-negative-amounts-conditional-style

November 10, 2015

November 5, 2015

Hi,

This post will give you the tips on displaying percentage values instead of usual category labels on HTML-5 pie chart and JFree chart.
There are many ways to get the percentage but this post is related with an use case.
Category and measure would be same field i.e,  count of same value/total count of field values.



Software Used for the sample in this post 
1) Jasper Design Studio Professional 6.0.1 (6.x)
2) PostgreSQL , a "test" database and a "DUMMY" table with the below shown data.

 

Use Case : 
% calculation on a single field count in below query.(Taking category and measure field as same).

Analysis : (23 is the total count of the field)
number of 1's -1 ---> 1/23
number of 2's- 2 ----> 2/23
number of 0's-10 ----> 10/23
number of 5's -2 ------> 2/23
number of 4's-2  -------> 2/23
number of 8's-2    ------>2/23
number of 10's -4   ------> 4/23

SELECT * FROM DUMMY
field1 field2
a    1
b    2
c    2
m    0
n    0
o    0
p    0
q    0
r    0
s    0
t    0
u    0
v    0
m1  5
n1  5
o1  4
p1 4
q1 8
r1 8
s1 10
t1 10
u1 10
v1 10

How to ? 
On HTML-5 Pie Chart.
On Title band 
1) Drag and drop HTML 5 pie chart to Title band and right click on the chart
      and be on "Chart properties" tab
2) Click on "Show Advanced Properties" tab at bottom right corner.
3) Click on "Add" button and give below property
   Property Name = plotOptions.pie.dataLabels.format
   Check "Use an expression" check box.
  Property Value= " {point.percentage:.0f} % "
4)  Click on Ok button and come back to main tabs of chart properties. i.e, click on "Chart Data"
   Click on Configuration tab 
   Under "Category Level" click on "Level1" and give below for this use case. 
 Expression : $F{field2}
 Value Class Name : java.lang.String 
 Order : Ascending 

 For conditional colors of slices - > Click on Bucket Properties and give below
 Click on Add
 Property Name : color
 Property Expression : 
$F{field2}.toString().equals("0") ? "#DEB887" : $F{field2}.toString().equals("1")? "#5F9EA0" : $F{field2}.toString().equals("2")? "#FF7F50" : $F{field2}.toString().equals("4")? "#006400" :
$F{field2}.toString().equals("5")? "#483D8B" : $F{field2}.toString().equals("8")? "#FF00FF" : "#ADFF2F"


5)  Now come to "Value section" 
Vale Definition Tab : 
Label Expression : "Measure label expression"
Calculation : Count
Value Expression : $F{field2}
Value Class Name : java.lang.Integer
Advanced  Properties 
Click on Add 
Contributor : SeriesItemProperty
Property Name : color
Use Bucket property value : Level1.color 

JFree Chart : 
To implement the JFree Bar chart for this particular data set and use case it is not as simple as we did for HTML-5. 
We need to do below work around.
1) Create a group with $F{field2}
2) Create two variables (one is to find the total count of field2 and another is to find the count of same field when the group changes).
i.e., 
Variable_1
Name = Variable_1
Value Class Name = java.lang.Integer 
Calculation = Count
Expression = $F{field2}
Increment Type = None
Reset Type = Report
Variable_2
Name = Variable_2
Value Class Name = java.lang.Integer 
Calculation = Count
Expression = $F{field2}
Increment Type = None
Reset Type =[Group] Group1  (note that Group1 is the name of the group created)

3) Drag and drop JFree pie chart to "Title band"  and right click on it and click on "Edit chart properties". 
 Give below properties on the windows.
Value = $V{Variable_2}
Key =$F{field2}.toString()
Click on "Finish" button and go the properties window of this chart .
Among 6 properties tabs for this chart,  click on "Chart Plot" tab and go the "Labels" section. 
Give Label Format = ({0} ) {2} 

NOTE: 
# Make sure created group by band height =0 to avoid empty spaces in the report.  
#  This report is not tested in Jaspeer server view but it should work.


That's all. you are done.! 

Save the report and preview. 


JRXML Code : 
 
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.0.1.final using JasperReports Library version 6.0.0  -->
<!-- 2015-11-06T01:00:22 -->
<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="Graph" pageWidth="1000" pageHeight="842" columnWidth="960" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="77404ba2-af1b-4f3a-be4c-93002d1edd4d">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="test_postgres"/>
    <property name="com.jaspersoft.studio.unit." value="pixel"/>
    <property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
    <queryString language="SQL">
        <![CDATA[select * from dummy]]>
    </queryString>
    <field name="filed1" class="java.lang.String"/>
    <field name="field2" class="java.lang.Integer"/>
    <variable name="Variable_1" class="java.lang.Integer" calculation="Count">
        <variableExpression><![CDATA[$F{field2}]]></variableExpression>
    </variable>
    <variable name="Variable_2" class="java.lang.Integer" resetType="Group" resetGroup="Group1" calculation="Count">
        <variableExpression><![CDATA[$F{field2}]]></variableExpression>
    </variable>
    <group name="Group1">
        <groupExpression><![CDATA[$F{field2}]]></groupExpression>
        <groupHeader>
            <band height="18"/>
        </groupHeader>
    </group>
    <title>
        <band height="369">
            <pieChart>
                <chart isShowLegend="false" evaluationTime="Report">
                    <reportElement x="540" y="0" width="420" height="369" uuid="fc0b804b-6c86-4cc8-845b-da2b015145f1"/>
                    <chartTitle/>
                    <chartSubtitle/>
                    <chartLegend/>
                </chart>
                <pieDataset>
                    <keyExpression><![CDATA[$F{field2}.toString()]]></keyExpression>
                    <valueExpression><![CDATA[$V{Variable_2}]]></valueExpression>
                </pieDataset>
                <piePlot labelFormat="({0} ) {2}" legendLabelFormat="{1}">
                    <plot/>
                    <itemLabel/>
                </piePlot>
            </pieChart>
            <componentElement>
                <reportElement x="0" y="0" width="467" height="369" uuid="bb305ca9-82de-4b15-91c1-4e285adf5640"/>
                <hc:chart xmlns:hc="http://jaspersoft.com/highcharts" xsi:schemaLocation="http://jaspersoft.com/highcharts http://jaspersoft.com/schema/highcharts.xsd" type="Pie" evaluationTime="Report">
                    <hc:chartSetting name="default">
                        <hc:chartProperty name="chart.zoomType">
                            <hc:propertyExpression><![CDATA["xy"]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="credits.enabled">
                            <hc:propertyExpression><![CDATA[false]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="credits.href">
                            <hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="credits.text">
                            <hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="legend.enabled">
                            <hc:propertyExpression><![CDATA[Boolean.FALSE]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="plotOptions.pie.dataLabels.format">
                            <hc:propertyExpression><![CDATA[" {point.percentage:.0f} % "]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="plotOptions.pie.showInLegend" value="false"/>
                        <hc:chartProperty name="title.text">
                            <hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
                        </hc:chartProperty>
                        <hc:chartProperty name="yAxis.title.text">
                            <hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
                        </hc:chartProperty>
                    </hc:chartSetting>
                    <multiAxisData>
                        <multiAxisDataset/>
                        <dataAxis axis="Rows">
                            <axisLevel name="Level1">
                                <labelExpression><![CDATA["Level Label expression"]]></labelExpression>
                                <axisLevelBucket class="java.lang.String">
                                    <bucketExpression><![CDATA[$F{field2}]]></bucketExpression>
                                    <bucketProperty name="color"><![CDATA[$F{field2}.toString().equals("0") ? "#DEB887" : $F{field2}.toString().equals("1")? "#5F9EA0" : $F{field2}.toString().equals("2")? "#FF7F50" : $F{field2}.toString().equals("4")? "#006400" :
$F{field2}.toString().equals("5")? "#483D8B" : $F{field2}.toString().equals("8")? "#FF00FF" : "#ADFF2F"





]]></bucketProperty>
                                </axisLevelBucket>
                            </axisLevel>
                        </dataAxis>
                        <multiAxisMeasure name="Measure1" class="java.lang.Integer" calculation="Count">
                            <labelExpression><![CDATA["Measure label expression"]]></labelExpression>
                            <valueExpression><![CDATA[$F{field2}]]></valueExpression>
                        </multiAxisMeasure>
                    </multiAxisData>
                    <hc:series name="Measure1">
                        <hc:contributor name="SeriesItemProperty">
                            <hc:contributorProperty name="color" valueType="Bucket" value="Level1.color"/>
                        </hc:contributor>
                    </hc:series>
                </hc:chart>
            </componentElement>
        </band>
    </title>
    <summary>
        <band height="33">
            <property name="local_mesure_unitheight" value="pixel"/>
            <property name="com.jaspersoft.studio.unit.height" value="px"/>
        </band>
    </summary>
</jasperReport>
 




References :  
http://community.jaspersoft.com/wiki/html5-bar-chart-how-add-percent-sign-datalabel-and-change-its-font-size

http://community.jaspersoft.com/wiki/html5-pie-chart-percentage-display

http://community.jaspersoft.com/wiki/displaying-percentage-pie-chart-labels

http://davidhoppmann.com/2013/11/26/customizing-tooltips-in-jasperreports-html5-chart-components/

http://api.highcharts.com/highcharts#plotOptions.pie.dataLabels.format

Colors : http://www.w3schools.com/html/html_colornames.asp










 

November 5, 2015

November 3, 2015

Hi ,
This post is about the issue while exporting the reports to Excel in Jasper Reports.

Problem Statement : 
Set font size of text field 10 and export it to excel from Jasper server. You will find size for text field as 9 instead of actual size.

Report Level settings :
In Report properties add this property
net.sf.jasperreports.export.xls.font.size.fix.enabled= false 

By default above property is true

Server Level settings : 
 # To set the fontSizeFixEnabled property to false.
 # It is available in xlsExportParameters bean that can be found in WEB-INF/applicationContext.xml file.
 # By default this property is set to true, causing the observed font decrease. 
# After restarting the server, fonts should appear with their actual size.


Reference :
http://community.jaspersoft.com/wiki/xls-exporter-decreases-size-arial-font-1-11-10how-fix

November 3, 2015

Pages

Feedback
randomness