How to embed 3rd party html page into the report? - html

How can i create this code for Jasperstudio, to display a page (by url) on a iframe within the report?
Using a text box, and html component.
<iframe src="demo_iframe.htm" name="iframe_a"></iframe>
<p>W3Schools.com</p>
Any direction would be helpful, this is the idea i have so far.
<componentElement>
<reportElement x="260" y="20" width="190" height="50" uuid="b7e534fb-15d5-4138-9522-793cf8d71afe">
<property name="net.sf.jasperreports.export.flash.element.allow.script.access" value="frame"/>
</reportElement>
<hc:html xmlns:hc="http://jasperreports.sourceforge.net/htmlcomponent" xsi:schemaLocation="http://jasperreports.sourceforge.net/htmlcomponent http://jasperreports.sourceforge.net/xsd/htmlcomponent.xsd" scaleType="RetainShape" horizontalAlign="Left" verticalAlign="Middle">
<hc:htmlContentExpression><![CDATA["page will be displayed here"]]></hc:htmlContentExpression>
</hc:html>
</componentElement>
<componentElement>
<reportElement x="0" y="20" width="190" height="50" uuid="b7e534fb-15d5-4138-9522-793cf8d71afe"/>
<hc:html xmlns:hc="http://jasperreports.sourceforge.net/htmlcomponent" xsi:schemaLocation="http://jasperreports.sourceforge.net/htmlcomponent http://jasperreports.sourceforge.net/xsd/htmlcomponent.xsd" scaleType="RetainShape" horizontalAlign="Left" verticalAlign="Middle">
<hc:htmlContentExpression><![CDATA["<a href='http://google.ca' target='frame'>click to go to google.ca</a>"]]></hc:htmlContentExpression>
</hc:html>
</componentElement>

Related

How to group dataset using JSON with Jasper Report?

I'm new to Jasper Report, and I'm using JSON as datasource. I have the following dataset, as a sample.
{"Northwind": {
"Customers": [
...
],
"Orders": [
{
"ShipPostalCode": 51100,
"ShippedDate": "1996-07-16",
"OrderDate": "1996-07-04",
"OrderID": 10248,
"Freight": 32.38,
"RequiredDate": "1996-08-01",
"ShipCity": "Berlin",
"ShipCountry": "Germany",
"EmployeeID": 5,
"ShipVia": 3,
"CustomerID": "ALFKI",
"ShipAddress": "59 rue de l'Abbaye",
"ShipName": "Vins et alcools Chevalier"
},
...
{
"ShipPostalCode": 44087,
"ShippedDate": "1996-07-10",
"OrderDate": "1996-07-05",
"OrderID": 10249,
"Freight": 11.61,
"RequiredDate": "1996-08-16",
"ShipCity": "Munich",
"ShipCountry": "Germany",
"EmployeeID": 6,
"ShipVia": 1,
"CustomerID": "RATTC",
"ShipAddress": "Luisenstr. 48",
"ShipName": "Martinez Gonzalez"
}
I'm passing the ShipCountry as parameter to my subreport, which is working as it should.
However, my template is showing the same data, twice, since it loops my dataset everytime for every object on my subset.
How group my orders by country ? How can I make to not show it duplicated ? Like this:
My country_orders_report.jrxml and country_order_list.jrxml code on GitHub. And my whole data, is very small :)
Hope that helps!
This happens because you have the same result for both queries in your main report and subreport.
In your main report - JsonCountryReport.jrxml - you have this query:
Northwind.Orders(ShipCountry == Germany)
that will produce 2 results. This implies rendering the subreport twice(for each query result).
Then, in your subreport - JsonCountryOrdersReport.jrxml - you have almost the same query:
Northwind.Orders(ShipCountry == $P{ShipCountry})
that will translate into the one above because you pass the same value for ShipCountry. The outcome should become obvious now.
You probably want to have:
Northwind.Customers(Country == Germany)
as your main report query with a Country field that you pass on to the subreport instead of ShipCountry.
EDIT: Since Orders' ShipCountry is only to be used, then you could use a ShipCountry group as #AlexK mentioned. However, placing the subreport in the groupHeader band is total overkill. You already have all the required data from your main query, so a subreport will not be necessary. You could restructure your main report as follows:
<?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="country_orders_report_new" pageWidth="595" pageHeight="842" columnWidth="515" leftMargin="40" rightMargin="40" topMargin="50" bottomMargin="50" uuid="bbe115b5-a5a0-4b39-9b73-7092dc59ab6d">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="JSON Data Adapter"/>
<style name="Sans_Normal" isDefault="true" fontName="DejaVu Sans" fontSize="12" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false"/>
<style name="Sans_Normal_8" style="Sans_Normal" fontSize="8"/>
<style name="Sans_Bold" fontName="DejaVu Sans" fontSize="12" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false"/>
<style name="Sans_Bold_8" style="Sans_Bold" fontSize="8"/>
<queryString language="json">
<![CDATA[Northwind.Orders]]>
</queryString>
<field name="ShipCountry" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="ShipCountry"/>
</field>
<field name="Id" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="OrderID"/>
</field>
<field name="OrderDate" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="OrderDate"/>
</field>
<field name="ShipCity" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="ShipCity"/>
</field>
<field name="Freight" class="java.lang.Float">
<property name="net.sf.jasperreports.json.field.expression" value="Freight"/>
</field>
<sortField name="ShipCountry"/>
<variable name="OrderNumber" class="java.lang.Integer" resetType="Group" resetGroup="ShipCountryGroup" calculation="Count">
<variableExpression><![CDATA[0]]></variableExpression>
</variable>
<variable name="TotalFreight" class="java.lang.Float" resetType="Group" resetGroup="ShipCountryGroup" calculation="Sum">
<variableExpression><![CDATA[$F{Freight}]]></variableExpression>
</variable>
<group name="ShipCountryGroup" isReprintHeaderOnEachPage="true">
<groupExpression><![CDATA[$F{ShipCountry}]]></groupExpression>
<groupHeader>
<band height="21">
<textField>
<reportElement style="Sans_Bold" x="5" y="5" width="100" height="15" isPrintWhenDetailOverflows="true" uuid="0aaeed6e-7ba1-4ab9-be59-d6ca702995fc"/>
<textFieldExpression><![CDATA[$F{ShipCountry}]]></textFieldExpression>
</textField>
<line>
<reportElement x="0" y="20" width="515" height="1" isPrintWhenDetailOverflows="true" uuid="6d76c22c-329f-4e77-a886-8580d3cb6bc1"/>
</line>
</band>
<band height="14">
<frame>
<reportElement mode="Opaque" x="0" y="2" width="356" height="10" forecolor="#CCFFFF" backcolor="#CCFFFF" uuid="e9af134f-31eb-48be-bd9b-292188f2554f"/>
<staticText>
<reportElement style="Sans_Bold_8" mode="Opaque" x="0" y="0" width="48" height="10" backcolor="#CCFFFF" uuid="62e5e770-7b05-4ecd-a254-ab0c7f643a37"/>
<textElement textAlignment="Right"/>
<text><![CDATA[ID]]></text>
</staticText>
<staticText>
<reportElement style="Sans_Bold_8" mode="Opaque" x="54" y="0" width="87" height="10" backcolor="#CCFFFF" uuid="c472f825-47f4-4e16-a782-cc4b02572cb0"/>
<textElement textAlignment="Center"/>
<text><![CDATA[Order Date]]></text>
</staticText>
<staticText>
<reportElement style="Sans_Bold_8" mode="Opaque" x="146" y="0" width="108" height="10" backcolor="#CCFFFF" uuid="89b5edba-1606-4f5d-89cb-144042c1fcdd"/>
<text><![CDATA[Ship City]]></text>
</staticText>
<staticText>
<reportElement style="Sans_Bold_8" mode="Opaque" x="259" y="0" width="92" height="10" backcolor="#CCFFFF" uuid="e7c6fbe3-ecb2-4c65-83d6-7c813448cec6"/>
<textElement textAlignment="Right"/>
<text><![CDATA[Freight]]></text>
</staticText>
</frame>
</band>
</groupHeader>
<groupFooter>
<band height="14">
<frame>
<reportElement mode="Opaque" x="0" y="2" width="356" height="10" forecolor="#33CCCC" backcolor="#33CCCC" uuid="084cfbb4-f390-4302-8bf5-2e65b34829b8"/>
<staticText>
<reportElement style="Sans_Bold_8" mode="Opaque" x="160" y="0" width="67" height="10" backcolor="#33CCCC" uuid="06753d49-aed5-46c8-be06-b107f81d7c2f"/>
<textElement textAlignment="Right"/>
<text><![CDATA[Total :]]></text>
</staticText>
<textField>
<reportElement style="Sans_Bold_8" mode="Opaque" x="227" y="0" width="27" height="10" backcolor="#33CCCC" uuid="d8edf4da-1e47-45ec-bbf3-f63b3bf0b93b"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$V{OrderNumber}]]></textFieldExpression>
</textField>
<textField pattern="¤ #,##0.00">
<reportElement style="Sans_Bold_8" mode="Opaque" x="259" y="0" width="92" height="10" backcolor="#33CCCC" uuid="a713b487-68a2-4391-a231-9bf9aa740090"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$V{TotalFreight}]]></textFieldExpression>
</textField>
</frame>
</band>
</groupFooter>
</group>
<title>
<band height="50">
<line>
<reportElement x="0" y="0" width="515" height="1" uuid="fc148b4e-50df-4a12-aa14-8505a4cfa6e1"/>
</line>
<staticText>
<reportElement style="Sans_Normal" x="0" y="10" width="515" height="30" uuid="5bf7651c-cd6b-4eaf-b65a-1413d60faab0"/>
<textElement textAlignment="Center">
<font size="22"/>
</textElement>
<text><![CDATA[Country Orders Report]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band height="21">
<staticText>
<reportElement style="Sans_Bold" mode="Opaque" x="0" y="5" width="515" height="15" forecolor="#FFFFFF" backcolor="#333333" uuid="da0f1cad-f552-424b-bf19-b41cabbfa4ac"/>
<text><![CDATA[Country Order List]]></text>
</staticText>
</band>
</pageHeader>
<detail>
<band height="14">
<textField>
<reportElement style="Sans_Normal_8" x="0" y="2" width="51" height="10" uuid="ec54687d-3c95-4647-9db5-fa71a6e81009"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$F{Id}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern="yyyy, MMM dd">
<reportElement style="Sans_Normal_8" positionType="Float" x="54" y="2" width="87" height="10" uuid="a112ba7b-c321-467c-91ec-ffb513c23338"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{OrderDate}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement style="Sans_Normal_8" positionType="Float" x="146" y="2" width="108" height="10" uuid="6a61edb3-239e-4791-a046-a6459343ac07"/>
<textFieldExpression><![CDATA[$F{ShipCity}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern="¤ #,##0.00">
<reportElement style="Sans_Normal_8" positionType="Float" x="259" y="2" width="92" height="10" uuid="61a8a117-6a43-46a7-9b96-10c5beb578ab"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$F{Freight}]]></textFieldExpression>
</textField>
</band>
</detail>
<pageFooter>
<band height="40">
<line>
<reportElement x="0" y="10" width="515" height="1" uuid="1371178a-a590-4616-affe-a4e1a24bcc84"/>
</line>
<textField>
<reportElement x="200" y="20" width="80" height="15" uuid="3eb302d8-0855-4f82-a666-3c9628dce372"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA["Page " + String.valueOf($V{PAGE_NUMBER}) + " of"]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement x="280" y="20" width="75" height="15" uuid="86f46fca-dbcb-4a60-b2f7-f8da6a4224f7"/>
<textFieldExpression><![CDATA[" " + String.valueOf($V{PAGE_NUMBER})]]></textFieldExpression>
</textField>
</band>
</pageFooter>
</jasperReport>

How can I generate same row multiple times?

I am trying to make a sticker using jasper report.
below image shows the structure.
I am passing a query to generate jasper report.
I have design the above structure in 'detail field' of jasper report so it can't repeat ,now I need to generate my query-result multiple times.
which means if currently my query gives me below result:-
I wish to produce the same result n times.
So If my query repeats the same row n times then it will automatically generate this structure 4 or n times
So anybody knows how to repeat the same row in mysql result query or anybody have better solution than this to do this job.
my expected result is as below
Modifying query is one solution example by using union
SELECT REPEAT('a',1) UNION SELECT REPEAT('b',10);
but I will give you a pure jasper-reports solution, defining a parameter that indicates how many times your print should be repeated
The pure jasper reports solution is using a subreport, passing an
JREmptyDatasource(nrOfPrints) and the fields as parameters. The subreport will repeat the detail band as many time as the nrOfPrints and you can output the parameters (your main report fields) in it.
Example
Main report
The parameter that defines how many times to repeat is RepeatNumber also see how I pass the fields as parameter to the subreport, you need to pass all your fields.
<?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="RepatDataSource" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="ceca1b98-d43c-4ee0-8339-661aa2ea53a9">
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["C:\\jdd\\projects\\StackTrace\\jasper\\"]]></defaultValueExpression>
</parameter>
<parameter name="RepeatNumber" class="java.lang.Integer">
<defaultValueExpression><![CDATA[3]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[Your query]]>
</queryString>
<field name="field1" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<detail>
<band height="100" splitType="Stretch">
<subreport>
<reportElement x="0" y="0" width="555" height="100" uuid="9d56da00-c1c9-4b2b-94e2-4019e4f58c8f"/>
<subreportParameter name="NR_REPEAT">
<subreportParameterExpression><![CDATA[$P{RepeatNumber}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="field1">
<subreportParameterExpression><![CDATA[$F{field1}]]></subreportParameterExpression>
</subreportParameter>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource($P{RepeatNumber}.intValue())]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "RepatDataSource_subreport.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
</jasperReport>
Subreport
<?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="RepatDataSource_subreport" pageWidth="555" pageHeight="802" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="98ddead4-e116-4c91-9ecb-416c10c3065c">
<parameter name="NR_REPEAT" class="java.lang.Integer"/>
<parameter name="field1" class="java.lang.String" isForPrompting="false"/>
<detail>
<band height="108" splitType="Stretch">
<textField>
<reportElement x="328" y="1" width="100" height="20" uuid="c5642fd7-9f63-4aa5-8503-16b1388c156b"/>
<textElement verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$V{REPORT_COUNT} + "/" +$P{NR_REPEAT}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="45" y="35" width="125" height="20" uuid="5c2bb49a-ba95-4cb7-8c46-c32a0769e5e9"/>
<textElement verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$P{field1}]]></textFieldExpression>
</textField>
<line>
<reportElement x="0" y="0" width="555" height="1" uuid="dd3e7e6c-979e-421b-9f71-479e64c8023b"/>
</line>
<staticText>
<reportElement x="0" y="35" width="45" height="20" uuid="0443e2f4-25bd-4837-9c95-bca2b26b3996"/>
<textElement verticalAlignment="Middle"/>
<text><![CDATA[Name]]></text>
</staticText>
<staticText>
<reportElement x="214" y="1" width="114" height="20" uuid="0e20ec29-0092-41a3-b977-f8f64ff842ea"/>
<textElement verticalAlignment="Middle"/>
<text><![CDATA[Print Educational Books]]></text>
</staticText>
</band>
</detail>
</jasperReport>
Output (with 1 record from my database)

How to calculate average time?

I am trying to figure out how to take the average of the Time To Buildof the items.
This is the equation I have used to gather the time:
($F{MO_DATECOMPLETED}.getTime()-$F{MO_DATECREATED}.getTime()) / (24* 60 * 60 * 1000) + " days " +
(($F{MO_DATECOMPLETED}.getTime()-$F{MO_DATECREATED}.getTime()) / (60 * 60 * 1000)) % 24 + " hour(s), " +
(($F{MO_DATECOMPLETED}.getTime()-$F{MO_DATECREATED}.getTime()) / (60 * 1000)) % 60 + " minute(s)"
This are the photos of my disign and variables, along with my XML, to help explain my situation.
QUESTION: How do I fix my avgToBuild variable so that it averages all of the calculated Time To Build?
<?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="BOM Build Time" pageWidth="595" pageHeight="840" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="775a7e35-9af8-4206-a155-b05a478c35b0">
<property name="ireport.zoom" value="1.5"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<parameter name="bomNumber" class="java.lang.String">
<parameterDescription><![CDATA[BOM Number:]]></parameterDescription>
</parameter>
<parameter name="To" class="java.util.Date"/>
<parameter name="From" class="java.util.Date"/>
<queryString>
<![CDATA[SELECT
datediff(day,MO."DATECREATED",MO."DATECOMPLETED") AS dayToBuild,
COMPANY."NAME" AS COMPANY_NAME,
BOM."NUM" AS BOM_NUM,
MO."DATECREATED" AS MO_DATECREATED,
MO."NUM" AS MO_NUM,
MO."DATECOMPLETED" AS MO_DATECOMPLETED,
MOITEM."BOMID" AS MOITEM_BOMID,
MOITEM."MOID" AS MOITEM_MOID,
MOITEM."QTYTOFULFILL" AS MOITEM_QTYTOFULFILL,
BOMITEMTYPE."ID" AS BOMITEMTYPE_ID,
WO."NUM" AS WO_NUM
FROM
"BOM" BOM INNER JOIN "MOITEM" MOITEM ON BOM."ID" = MOITEM."BOMID"
INNER JOIN "MO" MO ON MOITEM."MOID" = MO."ID"
INNER JOIN "BOMITEMTYPE" BOMITEMTYPE ON MOITEM."TYPEID" = BOMITEMTYPE."ID"
INNER JOIN "WO" WO ON MOITEM."ID" = WO."MOITEMID",
"COMPANY" COMPANY
WHERE
BOM."NUM"=$P{bomNumber}
AND MO."DATECOMPLETED" BETWEEN $P{From} AND $P{To}
ORDER BY
3 ASC]]>
</queryString>
<field name="DAYTOBUILD" class="java.lang.Long"/>
<field name="COMPANY_NAME" class="java.lang.String"/>
<field name="BOM_NUM" class="java.lang.String"/>
<field name="MO_DATECREATED" class="java.sql.Timestamp"/>
<field name="MO_NUM" class="java.lang.String"/>
<field name="MO_DATECOMPLETED" class="java.sql.Timestamp"/>
<field name="MOITEM_BOMID" class="java.lang.Integer"/>
<field name="MOITEM_MOID" class="java.lang.Integer"/>
<field name="MOITEM_QTYTOFULFILL" class="java.lang.Double"/>
<field name="BOMITEMTYPE_ID" class="java.lang.Integer"/>
<field name="WO_NUM" class="java.lang.String"/>
<variable name="timeToBuild" class="java.lang.String">
<variableExpression><![CDATA[($F{MO_DATECOMPLETED}.getTime()- $F{MO_DATECREATED}.getTime()) / (24* 60 * 60 * 1000) + " days " +
(($F{MO_DATECOMPLETED}.getTime()-$F{MO_DATECREATED}.getTime()) / (60 * 60 * 1000)) % 24 + " hour(s), " +
(($F{MO_DATECOMPLETED}.getTime()-$F{MO_DATECREATED}.getTime()) / (60 * 1000)) % 60 + " minute(s)"]]></variableExpression>
</variable>
<variable name="avgTimeToBuild" class="java.lang.String" calculation="Average">
<variableExpression><![CDATA[$V{timeToBuild}]]></variableExpression>
</variable>
<title>
<band height="27" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="555" height="25" uuid="40060ef5-07fd-4875-9f81-10b65d60d11d"/>
<textElement textAlignment="Center" verticalAlignment="Top">
<font size="16" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{COMPANY_NAME}]]></textFieldExpression>
</textField>
</band>
</title>
<pageHeader>
<band height="50">
<staticText>
<reportElement x="0" y="0" width="555" height="25" uuid="b17515a1-2396-49f1-ad96-452ce08d720e"/>
<textElement textAlignment="Center">
<font size="14"/>
</textElement>
<text><![CDATA[BOM Build Time Report]]></text>
</staticText>
<staticText>
<reportElement x="0" y="25" width="190" height="20" uuid="24836422-ce77-43c9-8268-a8f13d2d11b5"/>
<textElement textAlignment="Right">
<font size="14"/>
</textElement>
<text><![CDATA[Date Range:]]></text>
</staticText>
<textField>
<reportElement x="190" y="25" width="100" height="20" uuid="e25d36f8-e42b-4015-bc41-7bfbc9040119"/>
<textElement textAlignment="Right">
<font size="14"/>
</textElement>
<textFieldExpression><![CDATA[$P{From}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="290" y="25" width="20" height="20" uuid="45821608-63dc-459f-b2c3-41a6156b72dd"/>
<textElement textAlignment="Center">
<font size="14"/>
</textElement>
<text><![CDATA[-]]></text>
</staticText>
<textField>
<reportElement x="310" y="25" width="100" height="20" uuid="05fd3fd8-735d-402c-9d98-bdd3f9f52378"/>
<textElement>
<font size="14"/>
</textElement>
<textFieldExpression><![CDATA[$P{To}]]></textFieldExpression>
</textField>
</band>
</pageHeader>
<columnHeader>
<band height="24" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="75" height="20" uuid="b59f6065-7fc9-482d-9e08-e381ac697304"/>
<textElement>
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[BOM #]]></text>
</staticText>
<staticText>
<reportElement x="80" y="0" width="100" height="20" uuid="4ec40990-bdfe-415d-a7ae-b50e315d00ef"/>
<textElement>
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[Start Date]]></text>
</staticText>
<staticText>
<reportElement x="185" y="0" width="100" height="20" uuid="032d2ae9-99fe-4c6f-8cf4-24b9c5367a44"/>
<textElement>
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[Finish Date]]></text>
</staticText>
<staticText>
<reportElement x="415" y="0" width="140" height="20" uuid="55b731d5-b826-4ee1-b7d2-4a83cabd4ef8"/>
<textElement>
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[Time To Build]]></text>
</staticText>
<staticText>
<reportElement x="290" y="0" width="50" height="20" uuid="807ee552-ea26-4891-bc72-a433aeab1866"/>
<textElement>
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[QTY]]></text>
</staticText>
<staticText>
<reportElement x="345" y="0" width="50" height="20" uuid="cb39685d-f7c8-432f-9b69-454ff5fe2134"/>
<textElement>
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[WO #]]></text>
</staticText>
<line>
<reportElement x="0" y="19" width="555" height="1" uuid="266ffac8-70a0-4756-9191-5de40f532d9f"/>
</line>
</band>
</columnHeader>
<detail>
<band height="24" splitType="Stretch">
<textField isBlankWhenNull="true">
<reportElement x="0" y="0" width="75" height="20" isRemoveLineWhenBlank="true" uuid="3b256693-f18d-4ef9-89ec-7890481d1855"/>
<textFieldExpression><![CDATA[$F{BOM_NUM}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="80" y="0" width="100" height="20" isRemoveLineWhenBlank="true" uuid="7c01356e-4c95-4e15-9691-632e0b84946e"/>
<textFieldExpression><![CDATA[$F{MO_DATECREATED}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="185" y="0" width="100" height="20" isRemoveLineWhenBlank="true" uuid="516bc38e-99f3-486f-ae74-c8cfe6a5b5b1"/>
<textFieldExpression><![CDATA[$F{MO_DATECOMPLETED}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="415" y="0" width="140" height="20" isRemoveLineWhenBlank="true" uuid="aa538d4a-48ec-4b72-84ed-e9e889dcaee5"/>
<textElement>
<paragraph tabStopWidth="40"/>
</textElement>
<textFieldExpression><![CDATA[$V{timeToBuild}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="290" y="0" width="50" height="20" isRemoveLineWhenBlank="true" uuid="cf252514-6297-405d-a12e-6424332e6d10"/>
<textFieldExpression><![CDATA[$F{MOITEM_QTYTOFULFILL}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="345" y="0" width="50" height="20" isRemoveLineWhenBlank="true" uuid="6637a124-0145-4e56-b3eb-7af3bae5446e"/>
<textFieldExpression><![CDATA[$F{WO_NUM}]]></textFieldExpression>
</textField>
</band>
</detail>
<summary>
<band height="22">
<staticText>
<reportElement x="0" y="0" width="150" height="20" uuid="5ac0e1eb-dc7b-4866-88aa-3c1a9c3ef4a9"/>
<textElement>
<font size="12"/>
</textElement>
<text><![CDATA[Average Time To Build:]]></text>
</staticText>
<textField>
<reportElement x="150" y="0" width="150" height="20" uuid="860dd902-9791-443e-9a9d-3dedab365b23"/>
<textFieldExpression><![CDATA[$V{avgTimeToBuild}]]></textFieldExpression>
</textField>
</band>
</summary>
You need to calculate the average of the numeric value not the String value.
Lets calculate the average in milliseconds class="java.lang.Long"
<variable name="avgTimeToBuild" class="java.lang.Long" calculation="Average">
<variableExpression><![CDATA[$F{MO_DATECOMPLETED}.getTime()-$F{MO_DATECREATED}.getTime()]]></variableExpression>
</variable>
To display apply same expression as in "Time to Build" column using the variable $V{avgTimeToBuild}, even if in this case (since it in summary band) its not nessary I would put evaluationTime="Report" to make sure it's evaluated after displaying all records (if you move it in pageFooter this would be required)
<textField evaluationTime="Report">
<reportElement x="150" y="0" width="150" height="20" uuid="860dd902-9791-443e-9a9d-3dedab365b23"/>
<textFieldExpression><![CDATA[$V{avgTimeToBuild} / (24* 60 * 60 * 1000) + " days " + ($V{avgTimeToBuild} / (60 * 60 * 1000)) % 24 + " hour(s), " +($V{avgTimeToBuild} / (60 * 1000)) % 60 + " minute(s)"]]></textFieldExpression>
</textField>

How to get dynamic no of tables using json

I want to create Jasper Report with Dynamic no of tables.FOR EXAMPLE:
User 1 - 5 tables
User 2 - 3 tables
User 3 - 6 tables
I tried with list option but my tables are not visible and number of pages are getting increased.
<subDataset name="tableDataSet" uuid="c72d8dbd-d63e-411b-862d-a0d6e1e25d37">
<queryString language="json">
<![CDATA[tableData]]>
</queryString>
<field name="description" class="java.lang.String">
<fieldDescription><![CDATA[description]]></fieldDescription>
</field>
</subDataset>
<subDataset name="listDataSet" uuid="c72d8dbd-d63e-411b-862d-a0d6e1e25d37">
<queryString language="json">
<![CDATA[listData]]>
</queryString>
<field name="tableData" class="java.lang.String">
<fieldDescription><![CDATA[tableData]]></fieldDescription>
</field>
</subDataset>
<queryString language="json">
<![CDATA[mainDataSet]]>
</queryString>
<field name="listData" class="java.lang.String">
<fieldDescription><![CDATA[listData]]></fieldDescription>
</field>
<componentElement>
<reportElement x="-1" y="170" width="830" height="150" uuid="ab0272db-d740-42c9-94e5-238a2cc4a63e"/>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
<datasetRun subDataset="listDataSet" uuid="f80306fb-80fc-405b-b90d-f9fe6b6ee2e1">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("listData")]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="150" width="830">
<componentElement>
<reportElement positionType="Float" x="0" y="67" width="825" height="76" uuid="6a8e89c4-d4ea-4d8f-b932-8fbb24d00725"/>
<jr:table>
<datasetRun subDataset="tableDataSet" uuid="6ab7d349-34c8-4db7-bf3c-4e638ca36f5c">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("tableData")]]></dataSourceExpression>
</datasetRun>
<jr:column width="100" uuid="aae649c4-6a69-485f-8a0d-87022df793ee">
<jr:columnHeader style="colBotLeftLine" height="30">
<staticText>
<reportElement x="0" y="0" width="100" height="30" uuid="795dac43-0ff0-482c-89a0-7dac3b27d513"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[DESCRIPTION]]></text>
</staticText>
</jr:columnHeader>
<jr:columnFooter style="footerBotLeftLine" height="20">
<staticText>
<reportElement x="0" y="0" width="100" height="20" uuid="795dac43-0ff0-482c-89a0-7dac3b27d513"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Grand Total]]></text>
</staticText>
</jr:columnFooter>
<jr:detailCell height="20" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="100" height="20" uuid="734834e8-5896-4355-9454-6b188e86bfff"/>
<textFieldExpression><![CDATA[$F{description}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</jr:listContents>
</jr:list>
</componentElement>
Json Data.
{mainDataSet :
[
{CompanyName : "XYZ",
listData:
[
{tableId:1,
tableName:"Table One",
tableData:
[
{description:"Table One Row Data One "},
{description:"Table One Row Data Two"}
]
},
{tableId:2,
tableName:"Table Two",
tableData:
[
{description:"Table Two Row Data One "},
{description:"Table Two Row Data Two"}
]
}
]
}
]
}
mainDataSet is my Report Data Set, listData is the data for list and tableData is the one i want to display in my tables.
NOTE
If I remove the
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("tableData")]]></dataSourceExpression>
and put
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource()]]></dataSourceExpression>
Then Two tables are created with null values.
The query to main report let's leave it blank (and keep the mainDataSet node)
<queryString language="json"><![CDATA[]]></queryString>
Define the CompanyName field as
<field name="CompanyName" class="java.lang.String">
<fieldDescription><![CDATA[mainDataSet[0].CompanyName]]></fieldDescription>
</field>
The dataSourceExpression to pass to the jr:list
<datasetRun subDataset="listDataSet" uuid="71276e30-7777-44ae-b6d9-2087a4c51ca3">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("mainDataSet.listData")]]></dataSourceExpression>
</datasetRun>
Hence point to the mainDataSet.listData
The dataSourceExpression to pass to the table (we are now in the listData)
<datasetRun subDataset="tableDataSet" uuid="5bca90cb-1473-4ff6-82fc-1da5ae4fb44c">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("tableData")]]></dataSourceExpression>
</datasetRun>

Charts with Jasper Plugin does not show in Html format

I am using Jasper plugin to create charts in my app, I create a report with iReports and setup the chart, when I click on preview button the chart show well in iReports.
Then I copy the file to my reports app folder, I put a jasper tag in a list.gsp with PDF and HTML formats, run de application, and display the view, when I clic on PDF format the chart show well, but when I clic on HTML format the page show a broken image; the page tried to find the 'nullimg_0_0_9' image but it does not find it.
I put the report file in //web-app/reports/GraficaOperacionComercialProgramada.jrxml.
I am using Grails 1.3.6, Jasper Plugin 1.1.6.3 and iReports 4.0 on Ubuntu 10.10.
Any one know what I am do wrong?.
This is the code in my list.gsp:
<g:jasperReport
jasper="GraficaOperacionComercialProgramada"
format="${message(code: 'global.formatosReportes.label')}"
name="Gráfica sobre el total de carga por tipo de operación">
<br>
</g:jasperReport>
This is the report's code:
http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="GraficaOperacionComercialProgramada2" language="groovy" pageWidth="612" pageHeight="792" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
</textElement>
<text><![CDATA[Gráfica Concepto - Total de carga por categoría]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="20" splitType="Stretch">
<staticText>
<reportElement x="36" y="0" width="100" height="20"/>
<textElement>
</textElement>
<text><![CDATA[categoria]]></text>
</staticText>
<staticText>
<reportElement x="220" y="0" width="100" height="20"/>
<textElement>
</textElement>
<text><![CDATA[totalPasajeros]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="22" splitType="Stretch">
<textField>
<reportElement x="36" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{categoria}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="220" y="2" width="100" height="20"/>
<textElement/>
<textFieldExpression class="java.math.BigDecimal"><![CDATA[$F{totalPasajeros}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="340" splitType="Stretch">
<pieChart>
<chart>
<reportElement x="0" y="0" width="572" height="340"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<pieDataset>
<keyExpression><![CDATA[$F{categoria}]]></keyExpression>
<valueExpression><![CDATA[$F{totalPasajeros}]]></valueExpression>
<labelExpression><![CDATA[$F{categoria}]]></labelExpression>
</pieDataset>
<piePlot>
<plot/>
<itemLabel color="#000000" backgroundColor="#FFFFFF"/>
</piePlot>
</pieChart>
</band>
</summary>
</jasperReport>
Thanks in advance, ESalomon.
It sounds like you need to define your reports directory for jasper plugin. In grails-app/conf/Config.groovy make sure you have property named jasper.dir.reports and its value should be a full path to your jasper or jrxml files.