How to send multiple datasets using node-jasper library? - jasper-reports

I have a task to generate PDFs with nodeJS, so i am working with the node-jasper library.
what i want to know is how can i send multiple datasets in order to fill multiple charts. I can only send one dataset (the main dataset):/
here is my complete code:
const express = require('express')
var fs = require('fs')
const app = express()
const port = 5000
var jasper = require('node-jasper')({
path: './lib/jasperreports-6.10.0',
reports: {
hw: {
jasper: './jasperFiles/test.jasper',
jrxml: './reports/test.jrxml',
conn: 'in_memory_json'
}
},
});
app.get('/jasper1', (req, res) => {
var report = {
report: 'hw',
data: {
title: "test title",
dataset1: jasper.toJsonDataSource(
{
dados: [
{
c: "ar",
x: 'Arabe',
y: 20,
},
{
c: "en",
x: 'English',
y: 40,
}
]
},
'dados'
),
dataset2: jasper.toJsonDataSource(
{
dados: [
{
c: "eu",
x: 'Euro',
y: 15,
},
{
c: "usd",
x: 'Dollar',
y: 35,
}
]
},
'dados'
)
}
,
dataset:{},
}
var pdf = jasper.pdf(report);
res.set({
'Content-type': 'application/pdf',
'Content-Length': pdf.length
});
res.send(pdf)
});
app.listen(port, () => {
console.log('app is runing on port: ', port)
})
This the the report Design:
enter image description here
And This is the two datasets that i have created:
enter image description here
and this is my jrxml file:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.10.0.final using JasperReports Library version 6.10.0-unknown -->
<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="test" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="d2376d66-daf9-486d-877e-cc7f2fe28426">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<subDataset name="dataset1" uuid="80298b05-e1fd-427e-b7b5-c6a9e571d151">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="x" class="java.lang.String"/>
<field name="y" class="java.lang.Integer"/>
<field name="c" class="java.lang.String"/>
</subDataset>
<subDataset name="dataset2" uuid="a4f9409d-a1fa-45a5-a00b-d2f95b31573e">
<queryString>
<![CDATA[]]>
</queryString>
<field name="x" class="java.lang.String"/>
<field name="y" class="java.lang.Integer"/>
<field name="c" class="java.lang.String"/>
</subDataset>
<parameter name="title" class="java.lang.String"/>
<queryString>
<![CDATA[]]>
</queryString>
<background>
<band splitType="Stretch"/>
</background>
<columnHeader>
<band height="64" splitType="Stretch">
<staticText>
<reportElement x="50" y="0" width="103" height="64" uuid="6f999744-c4f9-48ef-a587-677dc644d77d"/>
<textElement>
<font size="26"/>
</textElement>
<text><![CDATA[Title]]></text>
</staticText>
<textField>
<reportElement x="140" y="10" width="100" height="30" uuid="e5a12f91-ddb4-445b-9f5b-57093703abaa"/>
<textFieldExpression><![CDATA[$P{title}]]></textFieldExpression>
</textField>
</band>
</columnHeader>
<detail>
<band height="604" splitType="Stretch">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.HorizontalRowLayout"/>
<pieChart>
<chart evaluationTime="Report">
<reportElement x="0" y="0" width="278" height="604" uuid="49052c41-6b67-42ed-9c84-c3089d3b2411"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<pieDataset maxCount="10">
<dataset>
<datasetRun subDataset="dataset1" uuid="7466bccc-a18d-4c68-801f-caac7533de69"/>
</dataset>
<keyExpression><![CDATA[$F{c}]]></keyExpression>
<valueExpression><![CDATA[$F{y}]]></valueExpression>
<labelExpression><![CDATA[$F{x}]]></labelExpression>
</pieDataset>
<piePlot>
<plot/>
<itemLabel/>
</piePlot>
</pieChart>
<pieChart>
<chart evaluationTime="Report">
<reportElement x="278" y="0" width="277" height="604" uuid="9f438f49-3f14-44b9-81a4-5f475ff6ecb2"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<pieDataset maxCount="10">
<dataset>
<datasetRun subDataset="dataset2" uuid="ce453374-bcf5-4b02-b8d9-35b263f143bc"/>
</dataset>
<keyExpression><![CDATA[$F{c}]]></keyExpression>
<valueExpression><![CDATA[$F{y}]]></valueExpression>
<labelExpression><![CDATA[$F{x}]]></labelExpression>
</pieDataset>
<piePlot>
<plot/>
<itemLabel/>
</piePlot>
</pieChart>
</band>
</detail>
<summary>
<band height="67" splitType="Stretch">
<staticText>
<reportElement x="180" y="10" width="151" height="51" uuid="da960c22-4947-49e0-9185-d2d39e21bcd7"/>
<textElement>
<font size="26"/>
</textElement>
<text><![CDATA[Footer]]></text>
</staticText>
</band>
</summary>
</jasperReport>
The problem is that when i run my code, the charts does not appear in the generated PDF, is this the right way to send datasets values ?
Can you help please ?

You need to declare the dataset1 and dataset2 parameters in the report and send them as data sources for the two chart subdatasets.
Like this (see the parameter definitions and the dataSourceExpression under datasetRun):
<parameter name="title" class="java.lang.String"/>
<parameter name="dataset1" class="net.sf.jasperreports.engine.JRDataSource"/>
<parameter name="dataset2" class="net.sf.jasperreports.engine.JRDataSource"/>
...
<detail>
<band height="604" splitType="Stretch">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.HorizontalRowLayout"/>
<pieChart>
<chart evaluationTime="Report">
<reportElement x="0" y="0" width="278" height="604" uuid="49052c41-6b67-42ed-9c84-c3089d3b2411"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<pieDataset maxCount="10">
<dataset>
<datasetRun subDataset="dataset1" uuid="7466bccc-a18d-4c68-801f-caac7533de69">
<dataSourceExpression><![CDATA[$P{dataset1}]]></dataSourceExpression>
</datasetRun>
</dataset>
<keyExpression><![CDATA[$F{c}]]></keyExpression>
<valueExpression><![CDATA[$F{y}]]></valueExpression>
<labelExpression><![CDATA[$F{x}]]></labelExpression>
</pieDataset>
<piePlot>
<plot/>
<itemLabel/>
</piePlot>
</pieChart>
<pieChart>
<chart evaluationTime="Report">
<reportElement x="278" y="0" width="277" height="604" uuid="9f438f49-3f14-44b9-81a4-5f475ff6ecb2"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<pieDataset maxCount="10">
<dataset>
<datasetRun subDataset="dataset2" uuid="ce453374-bcf5-4b02-b8d9-35b263f143bc">
<dataSourceExpression><![CDATA[$P{dataset2}]]></dataSourceExpression>
</datasetRun>
</dataset>
<keyExpression><![CDATA[$F{c}]]></keyExpression>
<valueExpression><![CDATA[$F{y}]]></valueExpression>
<labelExpression><![CDATA[$F{x}]]></labelExpression>
</pieDataset>
<piePlot>
<plot/>
<itemLabel/>
</piePlot>
</pieChart>
</band>
</detail>

Related

Weird positioning of elements inside a Jasper Report preview

I'm using TIBCO Jaspersoft® Studio 6.8.0 and I'm having some issues positioning things. I thought that the positioning would be kinda automatic following the GUI, but apparently it doesn't work like that.
I have a SubReport (no need for the master report right now) that calls other 2 SubReports, one for a pie chart and one for a crosstab. They both working pretty fine using subdataset from an external json (local json).
The problem is that I can't position them properly: I would need the pie chart to be positioned in the top part of the page, and the crosstab immediatly below.
Here's the subreport (used as master report now). You can see I'm using a mock (xml that calls a json), I will add the json at the end of the question.
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.8.0.final using JasperReports Library version 6.8.0-2ed8dfabb690ff337a5797129f2cd92902b0c87b -->
<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="ReportAnomalies_subReport" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="0a8e5b1c-8d35-4290-a283-c7fb4e197131">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="report\mock\TestTemp.xml"/>
<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="DefaultStyle" isDefault="true" fontName="SinaFont" fontSize="8"/>
<style name="DefaultTableStyle" style="DefaultStyle">
<box>
<pen lineWidth="0.5" lineColor="#888888"/>
</box>
</style>
<style name="DefaultTableHeaderStyle" style="DefaultTableStyle" mode="Opaque" backcolor="#F0F0F0"/>
<style name="Table_H" style="DefaultTableHeaderStyle"/>
<style name="Table_T" style="DefaultTableStyle"/>
<style name="Table_D" style="DefaultTableStyle"/>
<field name="NomeAnomalia" class="java.lang.String"/>
<field name="GruppiAnomalie" class="java.lang.Integer"/>
<field name="Total" class="java.lang.String"/>
<detail>
<band height="290">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<subreport>
<reportElement key="" x="10" y="0" width="535" height="290" uuid="37faa740-d0e0-457e-bb66-a9dbfc252683"/>
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("pieChartData")]]></dataSourceExpression>
<subreportExpression><![CDATA["ReportAnomalies_pieChart.jasper"]]></subreportExpression>
</subreport>
</band>
<band height="80">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<subreport>
<reportElement key="" style="DefaultTableStyle" x="10" y="0" width="535" height="80" uuid="ca3470c0-044b-4905-9524-5c0a948961a5">
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<property name="com.jaspersoft.studio.unit.y" value="px"/>
</reportElement>
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("anomalyList")]]></dataSourceExpression>
<subreportExpression><![CDATA["ReportAnomalies_crosstab.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
</jasperReport>
The pie chart subreport (I use the workaround <printWhenExpression><![CDATA[$F{print} == 1]]></printWhenExpression> because it will print the pie chart 3 times if not used)
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.8.0.final using JasperReports Library version 6.8.0-2ed8dfabb690ff337a5797129f2cd92902b0c87b -->
<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="ReportAnomalies_pieChart" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="0a8e5b1c-8d35-4290-a283-c7fb4e197131">
<property name="com.jaspersoft.studio.unit." value="pixel"/>
<style name="DefaultStyle" isDefault="true" fontName="SinaFont" fontSize="8"/>
<style name="DefaultTableStyle" style="DefaultStyle">
<box>
<pen lineWidth="0.5" lineColor="#888888"/>
</box>
</style>
<style name="DefaultTableHeaderStyle" style="DefaultTableStyle" mode="Opaque" backcolor="#F0F0F0"/>
<style name="Table_H" style="DefaultTableHeaderStyle"/>
<style name="Table_T" style="DefaultTableStyle"/>
<style name="Table_D" style="DefaultTableStyle"/>
<field name="print" class="java.lang.Integer"/>
<field name="severityName" class="java.lang.String"/>
<field name="severityValue" class="java.lang.Integer"/>
<field name="severityLabel" class="java.lang.String"/>
<detail>
<band height="285" splitType="Stretch">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<pieChart>
<chart evaluationTime="Report">
<reportElement style="DefaultTableStyle" x="40" y="0" width="420" height="280" uuid="65c16b4b-d856-4d7f-bb7b-a0c0aa0f3a3a">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<printWhenExpression><![CDATA[$F{print} == 1]]></printWhenExpression>
</reportElement>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<pieDataset maxCount="3">
<keyExpression><![CDATA[$F{severityName}]]></keyExpression>
<valueExpression><![CDATA[$F{severityValue}]]></valueExpression>
<labelExpression><![CDATA[$F{severityLabel}]]></labelExpression>
</pieDataset>
<piePlot>
<plot>
<seriesColor seriesOrder="0" color="#80E31E"/>
<seriesColor seriesOrder="1" color="#F09918"/>
<seriesColor seriesOrder="2" color="#DE3700"/>
</plot>
<itemLabel/>
</piePlot>
</pieChart>
</band>
</detail>
</jasperReport>
Now the crosstab subreport
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.8.0.final using JasperReports Library version 6.8.0-2ed8dfabb690ff337a5797129f2cd92902b0c87b -->
<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="Prova" pageWidth="595" pageHeight="842" orientation="Landscape" whenNoDataType="NoPages" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isSummaryNewPage="true" isSummaryWithPageHeaderAndFooter="true" uuid="1916d28f-c2ed-4735-a541-6dfbd82fe676">
<property name="com.jaspersoft.studio.unit." value="pixel"/>
<style name="DefaultStyle" isDefault="true" fontName="SinaFont" fontSize="8"/>
<style name="DefaultTableStyle" style="DefaultStyle">
<box>
<pen lineWidth="0.5" lineColor="#888888"/>
</box>
</style>
<style name="DefaultTableHeaderStyle" style="DefaultTableStyle" mode="Opaque" backcolor="#F0F0F0"/>
<style name="Table_H" style="DefaultTableHeaderStyle"/>
<style name="Table_T" style="DefaultTableStyle"/>
<style name="Table_D" style="DefaultTableStyle"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="NomeAnomalia" class="java.lang.String"/>
<field name="Value" class="java.lang.String"/>
<field name="Code" class="java.lang.String"/>
<field name="Severity" class="java.lang.String"/>
<field name="GruppiAnomalie" class="java.lang.String"/>
<variable name="VI" class="java.lang.Float">
<variableExpression><![CDATA[Float.parseFloat($F{Value})]]></variableExpression>
</variable>
<variable name="GruppiAnomalieI" class="java.lang.Integer">
<variableExpression><![CDATA[Integer.parseInt($F{GruppiAnomalie})]]></variableExpression>
</variable>
<group name="Group1">
<groupExpression><![CDATA[$V{GruppiAnomalieI}]]></groupExpression>
<groupFooter>
<band height="80">
<crosstab columnBreakOffset="20">
<reportElement x="30" y="0" width="520" height="70" uuid="af9d4537-350c-4e0b-a338-009d92c884d5">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
<property name="net.sf.jasperreports.export.headertoolbar.table.name" value=""/>
</reportElement>
<box leftPadding="3"/>
<crosstabDataset>
<dataset resetType="Group" resetGroup="Group1"/>
</crosstabDataset>
<rowGroup name="Severity1" width="30">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{Severity}]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents mode="Opaque" style="Table_H">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<textField>
<reportElement x="0" y="0" width="30" height="20" uuid="683211f0-a5a5-4cb4-aadc-658e5185baca">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$V{Severity1}.substring(4)]]></textFieldExpression>
</textField>
</cellContents>
</crosstabRowHeader>
<crosstabTotalRowHeader>
<cellContents mode="Opaque" style="Table_T">
<staticText>
<reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="b709de74-24d7-42d1-975c-3ff583a2f091"/>
<text><![CDATA[Totale Severity1]]></text>
</staticText>
</cellContents>
</crosstabTotalRowHeader>
</rowGroup>
<columnGroup name="Code1" height="20">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{Code}]]></bucketExpression>
</bucket>
<crosstabColumnHeader>
<cellContents mode="Opaque" style="Table_H">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<textField>
<reportElement x="0" y="0" width="25" height="20" uuid="8e897853-1771-4c8e-af55-24e5d5e3708a"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="7"/>
</textElement>
<textFieldExpression><![CDATA[$V{Code1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabColumnHeader>
<crosstabTotalColumnHeader>
<cellContents mode="Opaque" style="Table_T">
<staticText>
<reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="0423ca98-83a4-48b4-828b-ecc91f72c6df"/>
<text><![CDATA[Totale Code1]]></text>
</staticText>
</cellContents>
</crosstabTotalColumnHeader>
</columnGroup>
<measure name="Value_MEASURE1" class="java.lang.Float" calculation="Sum">
<measureExpression><![CDATA[$V{VI}]]></measureExpression>
</measure>
<measure name="NA" class="java.lang.String">
<measureExpression><![CDATA["n/a"]]></measureExpression>
</measure>
<crosstabCell width="25" height="20">
<cellContents mode="Opaque" style="Table_D">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<textField pattern="#,##0.##">
<reportElement x="0" y="0" width="25" height="20" uuid="8f7c6a83-bec1-4fdd-995b-c15df0712202"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="7"/>
</textElement>
<textFieldExpression><![CDATA[$V{Value_MEASURE1} == -1 ? $V{NA} : $V{Value_MEASURE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
</crosstab>
</band>
</groupFooter>
</group>
</jasperReport>
And finally the json file, very simple
[
{
"NomeAnomalia": "MIT Impalcati,Travi,Traversi CA CAP",
"GruppiAnomalie": 201,
"Total": "6%",
"anomalyList": [
{
"GruppiAnomalie": 201,
"Code": "cacap1",
"Name": "Macchie di umidita passiva",
"Severity": "0 - Lieve",
"Value": 3.2736806021763885
},
{
"GruppiAnomalie": 201,
"Code": "cacap12",
"Name": "Macchie di umidita passiva",
"Severity": "0 - Lieve",
"Value": 1.2736806021763885
},
{
"GruppiAnomalie": 201,
"Code": "cacap16",
"Name": "Macchie di umidita passiva",
"Severity": "2 - Forte",
"Value": 0.7736806021763885
},
{
"GruppiAnomalie": 201,
"Code": "DifGen1",
"Name": "Macchie di umidita passiva",
"Severity": "1 - Media",
"Value": 1.571812154
}
],
"pieChartData": [
{"print": 1, "severityName": "Lieve", "severityValue": 25, "severityLabel": "25%"},
{"print": 0, "severityName": "Media", "severityValue": 15, "severityLabel": "15%"},
{"print": 0, "severityName": "Forte", "severityValue": 38, "severityLabel": "38%"}
]
},
{
"NomeAnomalia": "MIT Pile,Spalle,Fondazioni CLS",
"GruppiAnomalie": 202,
"Total": "6%",
"anomalyList": [
{
"GruppiAnomalie": 202,
"Code": "cacap1",
"Name": "Macchie di umidita passiva",
"Severity": "0 - Lieve",
"Value": 3.2736806021763885
},
{
"GruppiAnomalie": 202,
"Code": "cacap12",
"Name": "Macchie di umidita passiva",
"Severity": "0 - Lieve",
"Value": 1.2736806021763885
},
{
"GruppiAnomalie": 202,
"Code": "cacap16",
"Name": "Macchie di umidita passiva",
"Severity": "2 - Forte",
"Value": 0.7736806021763885
}
],
"pieChartData": [
{"print": 1, "severityName": "Lieve", "severityValue": 25, "severityLabel": "5%"},
{"print": 0, "severityName": "Media", "severityValue": 15, "severityLabel": "87%"},
{"print": 0, "severityName": "Forte", "severityValue": 38, "severityLabel": "47%"}
]
}
]
I don't think the problem is to be found in subreports...at least not in the operational part, but I still don't know why it appears like this (3 pages instead of 2 and weird positioning)...they are in order, first, second and third page
Any suggestion?
The workaround you use in the pie chart subreport is causing the empty space in the generated report.
You set the print when expression for the pie chart element. That makes the pie chart not print for the second and third records, but the detail band itself will still consume its declared height even if the chart doesn't print.
A simple way to fix this is to set the print when expression for the band instead of the chart element. That will make the whole band not printing for the second and third records.
But a more normal solution would be to place the chart element in the summary band (with no print when expression), and remove the detail band altogether.

Jasper report unicode font not showing in PDF

I am using jasper report with Spring MVC. I have generated font.jar from jaspersoft studio 6.6.0 and add it to my application classpath. I am trying to use vrinda.ttf and sutonnyOMJ.ttf.
While the report is rendered properly in jasper studio, when I am using it from my application no unicode fonts are showing for PDF export. For excel export all values are showing properly but pdf is not working.
Font Family from my custom font.jar
<?xml version="1.0" encoding="UTF-8"?>
<fontFamilies>
<fontFamily name="vrinda">
<normal><![CDATA[fonts/vrinda/vrinda.ttf]]></normal>
<pdfEncoding><![CDATA[Identity-H]]></pdfEncoding>
<pdfEmbedded><![CDATA[true]]></pdfEmbedded>
<exportFonts>
<export key="net.sf.jasperreports.html">vrinda</export>
<export key="net.sf.jasperreports.xhtml">vrinda</export>
</exportFonts>
</fontFamily>
<fontFamily name="sutonny">
<normal><![CDATA[fonts/sutonny/SutonnyOMJ.ttf]]></normal>
<bold><![CDATA[fonts/sutonny/SutonnyMJ-Bold.ttf]]></bold>
<italic><![CDATA[fonts/sutonny/SutonnyMJ-Italic.ttf]]></italic>
<boldItalic><![CDATA[fonts/sutonny/SutonnyMJ-BoldItalic.ttf]]></boldItalic>
<pdfEncoding><![CDATA[Identity-H]]></pdfEncoding>
<pdfEmbedded><![CDATA[true]]></pdfEmbedded>
<exportFonts>
<export key="net.sf.jasperreports.html">SutonnyOMJ</export>
<export key="net.sf.jasperreports.xhtml">SutonnyOMJ</export>
</exportFonts>
</fontFamily>
</fontFamilies>
JRXML:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0 -->
<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="myName" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a43ee182-4df8-4ea4-b26f-b8b21078c9d1">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="dbname"/>
<queryString language="SQL">
<![CDATA[Query]]>
</queryString>
<field name="ClientName" class="java.lang.String">
<property name="com.jaspersoft.studio.field.label" value="ClientName"/>
<property name="com.jaspersoft.studio.field.tree.path" value="Table"/>
</field>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch">
<textField>
<reportElement x="20" y="5" width="500" height="30" uuid="f4900f30-da32-4cec-9142-10b111debcf3"/>
<textElement>
<font fontName="Vrinda" size="26"/>
</textElement>
<textFieldExpression><![CDATA["\u09AA\u09CD\u09B0\u09A4\u09BF\u09AC\u09C7\u09A6\u09A8"]]></textFieldExpression>
</textField>
</band>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch">
<staticText>
<reportElement x="82" y="0" width="100" height="30" uuid="b35f8d0e-5c47-46c7-b71c-c63dd7706724">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="9609ebcc-b3ae-4997-92b2-9aa48843434a"/>
</reportElement>
<textElement>
<font size="26"/>
</textElement>
<text><![CDATA[ClientName]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="125" splitType="Stretch">
<textField>
<reportElement x="82" y="64" width="308" height="30" uuid="ba9cab6a-2688-4601-bedb-3b62913a2cfb">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="9609ebcc-b3ae-4997-92b2-9aa48843434a"/>
</reportElement>
<textElement>
<font fontName="Vrinda" size="26"/>
</textElement>
<textFieldExpression><![CDATA[$F{ClientName}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
Java Code:
JasperReport jasperReport = JasperCompileManager.compileReport(reportSourceFile);
JasperPrint print = JasperFillManager.fillReport(jasperReport, params, reportRequestDTO.getConnection());
JRPdfExporter exporter = new JRPdfExporter();
ExporterInput exporterInput = new SimpleExporterInput(print);
exporter.setExporterInput(exporterInput);
OutputStreamExporterOutput exporterOutput = new SimpleOutputStreamExporterOutput(path);
exporter.setExporterOutput(exporterOutput);
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
exporter.setConfiguration(configuration);
exporter.exportReport();
pom.xml
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>6.5.1</version>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports-fonts</artifactId>
<version>6.0.0</version>
</dependency>
Excel Image for header unicode (Which is not showing in PDF)

List component displays only the first row

In my JasperReport's report only the first row of my collection gets displayed. Here is the relevant code.
The entity
public class LegendEntity implements Serializable{
private String label;
private Image bufferedImage;
public LegendEntity() {
}
public LegendEntity(String label) {
this.label = label;
}
public LegendEntity(String label,Image bufferedImage) {
this.label = label;
this.bufferedImage = bufferedImage;
}
//getters-setters
Preparing the datasource:
List<MyEntity> myEntitiesList = new ArrayList<>();
//filling the list
JRBeanCollectionDataSource entityDS= new JRBeanCollectionDataSource(myEntitiesList ,false);
report.getReportParameters().put("ENTITY_DATASOURCE", entityDS);
The jrxml:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport ... name="SampleReport" printOrder="Horizontal" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
<subDataset name="LegendDataset" uuid="e0d72aca-6fd5-4935-b57f-ff5a436f2afb">
<field name="label" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="bufferedImage" class="java.awt.Image"/>
</subDataset>
<parameter name="P_MAP_SCALE_STR" class="java.lang.String"/>
<parameter name="ENTITY_DATASOURCE" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
<detail>
<band height="842" splitType="Stretch">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.FreeLayout"/>
<frame>
<reportElement x="298" y="635" width="298" height="206" uuid="e807b35a-857c-43ba-a080-13f422eb1456"/>
<componentElement>
<reportElement x="11" y="11" width="275" height="186" uuid="d6f579d3-75de-4745-8f94-c974d2e697a0"/>
<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="LegendDataset" uuid="ee194811-e7e5-4102-83ff-b150901d73c9">
<dataSourceExpression><![CDATA[$P{ENTITY_DATASOURCE}]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="186" width="275">
<staticText>
<reportElement x="10" y="10" width="130" height="20" uuid="4260f10d-ee62-4cf6-8023-d0dc2266f4dd"/>
<textElement textAlignment="Center"/>
<text><![CDATA[ENTITY LABEL]]></text>
</staticText>
<staticText>
<reportElement x="150" y="10" width="100" height="20" uuid="88135c50-3c17-4b0f-b7e5-b05987f98b02"/>
<textElement textAlignment="Center"/>
<text><![CDATA[ENTITY SYMBOL]]></text>
</staticText>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="10" y="31" width="130" height="18" uuid="30885d06-38db-4b1c-a312-616a60ee1c42"/>
<textFieldExpression><![CDATA[$F{label}]]></textFieldExpression>
</textField>
<image>
<reportElement x="150" y="31" width="100" height="18" uuid="0020adca-acad-4915-9f0d-88d75e4897c7"/>
<imageExpression><![CDATA[$F{bufferedImage}]]></imageExpression>
</image>
</jr:listContents>
</jr:list>
</componentElement>
</frame>
<staticText>
<reportElement x="30" y="600" width="80" height="18" uuid="6c1afd65-a8d4-4e3f-9a56-d09abe7ec904"/>
<textElement textAlignment="Right">
<font fontName="DejaVu Sans" size="9" isBold="true"/>
</textElement>
<text><![CDATA[Ölçek: 1/]]></text>
</staticText>
<textField>
<reportElement positionType="Float" x="110" y="600" width="100" height="18" uuid="6360a545-63af-48cc-987d-d828c24a3b2a"/>
<textElement>
<font fontName="DejaVu Sans" size="9" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$P{P_MAP_SCALE_STR}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
And on the report only the first entity's label and symbol is displayed. What am I missing?
Debugging already done and I am sure that 1+ entities are present in the list.
The whole JRXML here .
You can try to put variables in white zone in table. Not in blue/header zone.
It works for me.
I have noticed at least 2 problems in your main JRXML:
Setting printOrder="Horizontal" at the report level may prevent proper elements overflow. Try reverting to printOrder="Vertical" or remove the attribute completely.
There is too much whitespace inside the list element that would force overflow. You should not have white space after the last elements.

How to add XY-line to bar chart creating a multitype chart with another axis?

Just wondering if there would be a possibility to create such a Jasper report chart that would be a combination of many chart types?
In my case I would like to combine Bar Chart and XY Line on two different axis. I already have a following kind of bar chart ready:
Ideally I would be able to add one XY-line in the same chart as well, which would present the cumulative value of the sum of all hour types for each month.See picture at the end. I have a feeling that this is not possible, and maybe I just should create a separate chart for the XY-line?
This is follow up on this question How to populate chart data with JavaBeans collection dataSet? (see my answer to understand further details if you like a simple bar chart and use the series expression dynamically)
To achieve a multi axis chart you should use <multiAxisChart> and it will become a little bit more complicated. We can not use the dynamic seriesExpression anymore and need to define each series manually, therefore I will use your original bean but still in a separated datasource.
Java bean
public class WorkingHours {
private int month = 0;
private double hoursNormal = 0;
private double hoursTravel = 0;
private double hoursOvertime = 0;
private double hoursTotalCumulative = 0;
public WorkingHours(int month, double hoursNormal, double hoursTravel, double hoursOvertime, double hoursTotalCumulative) {
super();
this.month = month;
this.hoursNormal = hoursNormal;
this.hoursTravel = hoursTravel;
this.hoursOvertime = hoursOvertime;
this.hoursTotalCumulative = hoursTotalCumulative;
}
//getter and setter
}
Fill with data (use your logic) and pass as java.util.List in parameter
List<WorkingHours> list = new ArrayList<WorkingHours>();
list.add(new WorkingHours(1, 2.3, 1.2, 2.1,4.1));
list.add(new WorkingHours(2, 5.3, 2.2,3, 9.1));
list.add(new WorkingHours(3, 3.1, 0.5, 2.0, 20.5));
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("CHART_DATA", list);
The report (jrxml)
<?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="working_hours" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="1a12c021-57e2-4482-a273-56cbd3f78a17">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<subDataset name="chartDataSet" uuid="119b7f0e-01ef-4e2b-b628-d76f51e83768">
<field name="month" class="java.lang.Integer"/>
<field name="hoursNormal" class="java.lang.Double"/>
<field name="hoursTravel" class="java.lang.Double"/>
<field name="hoursOvertime" class="java.lang.Double"/>
<field name="hoursTotalCumulative" class="java.lang.Double"/>
</subDataset>
<parameter name="CHART_DATA" class="java.util.List" isForPrompting="false"/>
<summary>
<band height="282" splitType="Stretch">
<multiAxisChart>
<chart evaluationTime="Report">
<reportElement x="62" y="17" width="419" height="235" uuid="8a16251e-8c1a-4384-8487-9be8f6c274e5"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend position="Right"/>
</chart>
<multiAxisPlot>
<plot/>
<axis position="rightOrBottom">
<lineChart>
<chart evaluationTime="Report">
<reportElement positionType="Float" x="0" y="25" width="270" height="175" backcolor="#FFFFFF" uuid="4a755d76-1350-4921-a0be-20ae9e485e12"/>
<chartTitle color="#000000"/>
<chartSubtitle color="#000000"/>
<chartLegend textColor="#000000" backgroundColor="#FFFFFF" position="Right"/>
</chart>
<categoryDataset>
<dataset>
<datasetRun subDataset="chartDataSet" uuid="abec2dce-b670-4e84-b71f-469d954dbcb5">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{CHART_DATA})]]></dataSourceExpression>
</datasetRun>
</dataset>
<categorySeries>
<seriesExpression><![CDATA["Total Cum"]]></seriesExpression>
<categoryExpression><![CDATA[$F{month}]]></categoryExpression>
<valueExpression><![CDATA[$F{hoursTotalCumulative}]]></valueExpression>
</categorySeries>
</categoryDataset>
<linePlot isShowLines="true" isShowShapes="true">
<plot>
<seriesColor seriesOrder="0" color="#9900CC"/>
</plot>
<categoryAxisFormat>
<axisFormat/>
</categoryAxisFormat>
<valueAxisLabelExpression><![CDATA["Total Cum"]]></valueAxisLabelExpression>
<valueAxisFormat>
<axisFormat labelColor="#000000" tickLabelColor="#000000" tickLabelMask="#,##0" axisLineColor="#000000"/>
</valueAxisFormat>
</linePlot>
</lineChart>
</axis>
<axis>
<barChart>
<chart evaluationTime="Report">
<reportElement x="0" y="0" width="0" height="0" backcolor="#FFFFFF" uuid="723abd06-b593-422a-b679-043084525a8c"/>
<chartTitle color="#000000"/>
<chartSubtitle color="#000000"/>
<chartLegend textColor="#000000" backgroundColor="#FFFFFF" position="Right"/>
</chart>
<categoryDataset>
<dataset>
<datasetRun subDataset="chartDataSet" uuid="abec2dce-b670-4e84-b71f-469d954dbcb5">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{CHART_DATA})]]></dataSourceExpression>
</datasetRun>
</dataset>
<categorySeries>
<seriesExpression><![CDATA["Normal"]]></seriesExpression>
<categoryExpression><![CDATA[$F{month}]]></categoryExpression>
<valueExpression><![CDATA[$F{hoursNormal}]]></valueExpression>
</categorySeries>
<categorySeries>
<seriesExpression><![CDATA["Travel"]]></seriesExpression>
<categoryExpression><![CDATA[$F{month}]]></categoryExpression>
<valueExpression><![CDATA[$F{hoursTravel}]]></valueExpression>
</categorySeries>
<categorySeries>
<seriesExpression><![CDATA["Overtime"]]></seriesExpression>
<categoryExpression><![CDATA[$F{month}]]></categoryExpression>
<valueExpression><![CDATA[$F{hoursOvertime}]]></valueExpression>
</categorySeries>
</categoryDataset>
<barPlot>
<plot/>
<itemLabel/>
<categoryAxisFormat>
<axisFormat/>
</categoryAxisFormat>
<valueAxisLabelExpression><![CDATA["h"]]></valueAxisLabelExpression>
<valueAxisFormat>
<axisFormat labelColor="#000000" tickLabelColor="#000000" tickLabelMask="#,##0" axisLineColor="#000000"/>
</valueAxisFormat>
</barPlot>
</barChart>
</axis>
</multiAxisPlot>
</multiAxisChart>
</band>
</summary>
</jasperReport>
Key points:
We use <multiAxisChart> with 2 <axis> on one the <lineChart> on the other <barChart>, for the <barChart> we define every <categorySeries> separately.
Output
For more demos on chart see this: Jasper Reports Chart Samples

Why an empty report is being created in Jasper Reports

I am new to Jasper Reports , cpuld anybody please tell me why an empty Report is being created inspite of data being resent in Database
please see this is my program
public class ReportDriver {
/**
* Constructor for ReportDriver
*/
public ReportDriver() {
}
public static void main(String args[]) {
Connection con = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(
"jdbc:oracle:thin:#localhost:1521:orcle", "scott", "tiger");
JasperDesign jasperDesign = JRXmlLoader
.load("C:\\Documents and Settings\\Admin\\report5.jrxml");
JasperReport jasperReport = JasperCompileManager
.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(
jasperReport, null, con);
JasperViewer.viewReport(jasperPrint);
} catch (Exception ex) {
ex.printStackTrace();
String connectMsg = "Could not create the report ";
System.out.println(connectMsg);
}
}
}
This is my jrxml file
<?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="report5" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<queryString language="SQL">
<![CDATA[select EMPNO , ENAME , JOB from emp]]>
</queryString>
<field name="EMPNO" class="java.math.BigDecimal"/>
<field name="ENAME" class="java.lang.String"/>
<field name="JOB" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="125" splitType="Stretch"/>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
Your report is empty because that's exactly how it should be: Your jrxml does not include any elements to display. Try the following jrxml and see the difference:
<?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="report5" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<queryString language="SQL">
<![CDATA[select EMPNO , ENAME , JOB from emp]]>
</queryString>
<field name="EMPNO" class="java.math.BigDecimal"/>
<field name="ENAME" class="java.lang.String"/>
<field name="JOB" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="125" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{EMPNO}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="20" width="100" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{ENAME}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="40" width="100" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{JOB}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>