Was created pie 3d chart. It has several params. For example, one of them call "errors" and another - "success". Both is Integer. If values are different, for example 10 and 9, all work fine, but if values are equal, it draw like one pie, and in label expression writed only one value.
In this image I set 10 errors and 10 success, but as can be seen, JasperReports draw just 10 success.
I check it in iReport and by generation report in Java, but results was same.
One more example.
<parameter name="access" class="java.lang.Number"/> set 10
<parameter name="configChange" class="java.lang.Number"/> set 10
<parameter name="creating" class="java.lang.Number"/> set 5
<parameter name="deleting" class="java.lang.Number"/> set 10
<parameter name="updating" class="java.lang.Number"/> set 5
<parameter name="objRequest" class="java.lang.Number"/> set 7
<parameter name="unknown" class="java.lang.Number"/> set 8
Result:
jrxml-file:
<pie3DChart>
<chart isShowLegend="true" renderType="draw" theme="default">
<reportElement uuid="1ea2fe12-8478-48a3-8a16-828cb17bc242" positionType="FixRelativeToBottom" mode="Opaque" x="0" y="50" width="430" height="280" backcolor="#CCFFFF"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<pieDataset>
<pieSeries>
<keyExpression><![CDATA[$P{errors}]]></keyExpression>
<valueExpression><![CDATA[$P{errors}]]></valueExpression>
<labelExpression><![CDATA["Error"]]></labelExpression>
</pieSeries>
<pieSeries>
<keyExpression><![CDATA[$P{success}]]></keyExpression>
<valueExpression><![CDATA[$P{success}]]></valueExpression>
<labelExpression><![CDATA["Success"]]></labelExpression>
</pieSeries>
</pieDataset>
<pie3DPlot depthFactor="0.2">
<plot backgroundAlpha="0.1" foregroundAlpha="0.6">
<seriesColor seriesOrder="0" color="#FF0000"/>
<seriesColor seriesOrder="1" color="#0066FF"/>
</plot>
<itemLabel/>
</pie3DPlot>
</pie3DChart>
Related
I am generating a report having a table and a Line graph.
The master report dataset returns 8 records. So, I need 8 pages with each page displaying data for each record. I have mapped the field from master dataset to both the table and line graph's dataset.
The table is displayed 8 times perfectly with the correct param value.
But, the line graph always shows data for the last parameter value.
Jrxml Content:
<?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="chart" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="66962ca4-5579-453f-a9fe-5d7284566dc1">
<subDataset name="chartDS" uuid="74b2bdf1-5e99-43ec-94c6-f6c999ea449c">
<parameter name="deviceId" class="java.lang.Long"/>
<queryString language="SQL">
<![CDATA[SELECT
ticket.descr,
IFNULL(SUM(diff)/60, 0) as duration,
DATE(ticket.created_date) as date
FROM
(SELECT
t.id, t.created_date, t.restored_date, E.descr,TIMESTAMPDIFF(SECOND,t.created_date,t.restored_date) as diff
FROM
ticket t
Inner JOIN (SELECT DISTINCT
description AS descr
FROM
alarm_config
WHERE
enabled = 1
AND site_location_device_id = $P{deviceId} ) E ON t.description LIKE CONCAT('%', E.descr, '%')
AND t.site_location_device_id = $P{deviceId}
ORDER BY E.descr) ticket
GROUP BY ticket.descr, DATE(ticket.created_date)
ORDER BY DATE(ticket.created_date)]]>
</queryString>
<field name="descr" class="java.lang.String"/>
<field name="duration" class="java.math.BigDecimal"/>
<field name="date" class="java.sql.Date"/>
</subDataset>
<queryString language="SQL">
<![CDATA[SELECT
sl.location_name,sld.id as deviceId ,sld.name
FROM
site
INNER JOIN
site_location sl ON site.id = sl.site_id
INNER JOIN
site_location_device sld ON sl.id = sld.site_location_id
where site_id = 32 and sld.device_type_id = (SELECT id FROM device_type WHERE name LIKE 'HSS')
]]>
</queryString>
<field name="location_name" class="java.lang.String"/>
<field name="deviceId" class="java.lang.Long"/>
<field name="name" class="java.lang.String"/>
<detail>
<band height="273" splitType="Stretch">
<barChart>
<chart evaluationTime="Report">
<reportElement x="20" y="23" width="514" height="200" uuid="53f820c6-7e46-4052-bcdf-65d3a4b9cf15"/>
<chartTitle>
<titleExpression><![CDATA[$F{deviceId}]]></titleExpression>
</chartTitle>
<chartSubtitle/>
<chartLegend/>
</chart>
<categoryDataset>
<dataset>
<datasetRun subDataset="chartDS" uuid="94e17f1e-b5a7-4b22-9864-481fc0adf56b">
<datasetParameter name="deviceId">
<datasetParameterExpression><![CDATA[$F{deviceId}]]></datasetParameterExpression>
</datasetParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
</dataset>
<categorySeries>
<seriesExpression><![CDATA[$F{descr}]]></seriesExpression>
<categoryExpression><![CDATA[$F{date}]]></categoryExpression>
<valueExpression><![CDATA[$F{duration}]]></valueExpression>
</categorySeries>
</categoryDataset>
<barPlot>
<plot labelRotation="54.0"/>
<itemLabel/>
<categoryAxisFormat labelRotation="54.0">
<axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/>
</categoryAxisFormat>
<valueAxisFormat>
<axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/>
</valueAxisFormat>
</barPlot>
</barChart>
</band>
</detail>
</jasperReport>
PS: Both table and graph are in the detail section.
Also, I am trying this from eclipse - report designer plugin
Finally, I managed to solve the problem.
The issue was with the evaluation time of the chart's expression.
It was by mistake set to "Report".I changed it to "Now".
Replaced this
<chart evaluationTime="Report">
with below
<chart evaluationTime="Now">
evaluationTime − Determines when the chart's expression will be evaluated. Values could be Now, Report, Page, Column, Group, Band. The default value is Now
I have following data set in oracle table and want to generate CSV file from that data.
My data
CaseID Amount
1000 10
1000 20
1000 50
2000 30
2000 10
3000 30
3000 20
3000 20
It is necessary to show the following output from above data.
Required Output
CaseID Amount Aggregate
1000 10
1000 20
1000 50 80
2000 30
2000 10 40
3000 30
3000 20
3000 20 70
Aggregate column is populated by accumulating the sum of Amount according to caseID group.
Group summary should display on last element of the group. But not in the next row, should display in the same row and next column, that matching with the last element.
I tried with 'Print When Expression' for other scenarios, but unable to use with this scenario. Also I have find similar questions, but not cater with this requirement. So would like to know the possible solutions for this.
You can do something similar with evaluationTime="Auto". You can have a text element that shows the value on the last record in the group and is empty for other records. It's not the same as not printing the element at all, but you can't use the print when expression because it doesn't have delayed evaluation.
evaluationTime="Auto" uses the reset types of variables to decide the moment at which it reads the variable values. Each group has an automatically created count variable that resets with the group, and if you create a new variable that resets on each record you can use it to determine if the current record is the last record in the group.
The whole report would look something like this
<?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="report" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" resourceBundle="jasperreports" whenResourceMissingType="Key" isIgnorePagination="true" uuid="816687ff-bb19-4f6b-a2b6-53634ce095fc">
<style name="dd" isDefault="true" fontSize="10"/>
<field name="CaseID" class="java.lang.Integer"/>
<field name="Amount" class="java.lang.Integer"/>
<variable name="AmountSum" class="java.lang.Integer" resetType="Group" resetGroup="CaseIDGroup" calculation="Sum">
<variableExpression><![CDATA[$F{Amount}]]></variableExpression>
</variable>
<variable name="GroupCurrentCount" class="java.lang.Integer" resetType="None">
<variableExpression><![CDATA[$V{CaseIDGroup_COUNT}]]></variableExpression>
</variable>
<group name="CaseIDGroup">
<groupExpression><![CDATA[$F{CaseID}]]></groupExpression>
</group>
<detail>
<band height="20">
<textField>
<reportElement x="0" y="0" width="100" height="20" uuid="af7a5ea9-ffcb-4a7f-aaa8-7d5cab06a579"/>
<textFieldExpression><![CDATA[$F{CaseID}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="100" y="0" width="100" height="20" uuid="a7e2795e-456a-4c6e-946f-8315df453b1f"/>
<textFieldExpression><![CDATA[$F{Amount}]]></textFieldExpression>
</textField>
<textField evaluationTime="Auto" isBlankWhenNull="true">
<reportElement x="200" y="0" width="100" height="20" uuid="afda4fcc-78fc-46f9-8c5c-2e0c4f04dfa5"/>
<textFieldExpression><![CDATA[$V{GroupCurrentCount}.equals($V{CaseIDGroup_COUNT}) ? $V{AmountSum} : null]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
I have to create a bar chart which can have a large amount (around 50) of categories (X Axis). I wish to split this report into multiple pages so that I can apply pagination. I have found an answer here:
How can I generate paginated bar chart in jasper report
But the above answer discusses a bar chart with single series.
Following is a sample report which I intend to create:
Assuming we have around 50 dates in X axis, the report will become large. So I have to break this report such that I am showing a configurable amount (say 3) of categories per page. Following is my approach:
Create a group of date field
Create a variable which counts this group.
Create another group with groupExpression $V{variable1} - 1 - ( ($V{variable1} - 1) % 3 )
Following is the 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="paginationBar3d" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a9331cff-3045-47b5-8399-17a89e2ac39c">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
<![CDATA[select a.year_built, aty.description, count(*) as count
from aircraft a, aircraft_types aty
where a.aircraft_type_id = aty.aircraft_type_id
group by year_built, description order by a.year_built;]]>
</queryString>
<field name="year_built" class="java.sql.Date">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="description" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="count" class="java.lang.Long"/>
<variable name="variable1" class="java.lang.Integer" incrementType="Group" incrementGroup="yearGroup" calculation="Count">
<variableExpression><![CDATA[Boolean.TRUE]]></variableExpression>
</variable>
<group name="yearGroup">
<groupExpression><![CDATA[$F{year_built}]]></groupExpression>
</group>
<group name="splitter">
<groupExpression><![CDATA[$V{variable1} - 1 - ( ($V{variable1} - 1) % 3)]]></groupExpression>
<groupFooter>
<band height="802">
<bar3DChart>
<chart>
<reportElement uuid="7114e305-2cfb-4757-b034-b0a12dd412d9" x="0" y="0" width="555" height="802"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<categoryDataset>
<dataset resetType="Group" resetGroup="splitter"/>
<categorySeries>
<seriesExpression><![CDATA[$F{description}]]></seriesExpression>
<categoryExpression><![CDATA[$F{year_built}]]></categoryExpression>
<valueExpression><![CDATA[$F{count}]]></valueExpression>
</categorySeries>
</categoryDataset>
<bar3DPlot>
<plot/>
<itemLabel/>
<categoryAxisFormat>
<axisFormat/>
</categoryAxisFormat>
<valueAxisFormat>
<axisFormat/>
</valueAxisFormat>
</bar3DPlot>
</bar3DChart>
</band>
</groupFooter>
</group>
</jasperReport>
This generates a single category per page. What should be the correct approach in this scenario?
This can be done using Reports Group, I have done it earlier ,
You can try this Link :-
Split a chart in to multiple pages
and just replace
$V{REPORT_COUNT} - 1 - ( ($V{REPORT_COUNT} - 1) % 3 )
with
$V{REPORT_COUNT} - 1 - ( ($V{REPORT_COUNT} - 1) % 18 )
The above report works as intended if I define yearGroup after splitter. I am not sure how ordering of groups matter.
I have a problem with JasperReports. I want to group the records depending on one specific column's value.
For example input data:
Name--email--PledgeType--amount
aaa--aa#yahoo.com--1--20.00
bbb--bb#yahoo.com--2--30.00
ccc--cc#gmai.com--1--35.00
ddd--dd#gmai.com--2-- 40.00
The output report will be grouped by the "PledgeType" value (1, 2, ... number):
Total for group one: 55.00
Name email amount
aaa aa#yahoo.com 20.00
ccc cc#gmai.com 35.00
------------------------------------
Total for group two: 70.00
Name email amount
bbb bb#yahoo.com 30.00
ddd dd#gmai.com 40.00
Can JasperReports solve this problem? how?
You can define grouping in JasperReports. JasperReports calculates the total for you, there is comfortable way to add groups and totals. Here an overview what you need to do in iReport.
To add the group
modify your query to order by pledgeType - JasperReports requires the data sorted according to your grouping.
right click on the report in the report inspector and choose Add Report Group.
Follow the wizard, set as group name PledgeType and choose Group by the following report object where you select the field PledgeType. Click next. Check Add the group header and click Finish.
To add the total
right click on variables in the report inspector and choose Add Variable.
In the properties panel choose this configuration: Variable class: BigDecimal, Calculation: Sum, ResetType: Group, ResetGroup PledgeType, Variable Expression: $F{amount}.
Drag & drop the variable into the group header in the report designer. Click on the field and change: Text field expression: "Total for group " + $F{PledgeType} + ": " + $V{totalPledge}, Expression Class: java.lang.String. Evaluation time: Group. Evaluation Group: PledgeType.
Info: The evaluation time decides when a variable gets evaluated, i.e. when the sum of the calculation will be shown. If you set it to group it means 'once the group processing is completed'.
Attached the generated report and the JRXML.
The JRXML is created with iReport 5.0 - however, if you follow the steps above it should work with JR v 2+
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report2" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="ce08fe1c-1543-4460-8613-7f03b200082b">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
<![CDATA[select * from
(select 'aaa' as Name, 'aa#yahoo.com' as email, 1 as PledgeType, 20.00 as amount
union select 'bbb', 'bb#yahoo.com' ,2, 30.00
union select 'ccc', 'cc#gmai.com' ,1, 35.00
union select 'ddd', 'dd#gmai.com' ,2, 40.00) tbl
order by PledgeType]]>
</queryString>
<field name="Name" class="java.lang.String"/>
<field name="email" class="java.lang.String"/>
<field name="PledgeType" class="java.lang.Long"/>
<field name="amount" class="java.math.BigDecimal"/>
<variable name="totalPledge" class="java.math.BigDecimal" resetType="Group" resetGroup="PledgeType" calculation="Sum">
<variableExpression><![CDATA[$F{amount}]]></variableExpression>
</variable>
<group name="PledgeType">
<groupExpression><![CDATA[$F{PledgeType}]]></groupExpression>
<groupHeader>
<band height="61">
<textField evaluationTime="Group" evaluationGroup="PledgeType">
<reportElement uuid="401c7b3b-af73-4d40-8982-9c1692eb7085" x="0" y="21" width="555" height="20"/>
<textElement/>
<textFieldExpression><![CDATA["Total for group " + $F{PledgeType} + ": " + $V{totalPledge}]]></textFieldExpression>
</textField>
<staticText>
<reportElement uuid="87cd0d21-014d-4e6c-a54a-006165a38414" x="0" y="41" width="185" height="20"/>
<textElement/>
<text><![CDATA[Name]]></text>
</staticText>
<staticText>
<reportElement uuid="bd0fc2f5-4963-4c9d-a9be-3659be06e436" x="185" y="41" width="185" height="20"/>
<textElement/>
<text><![CDATA[email]]></text>
</staticText>
<staticText>
<reportElement uuid="5d5d7ce1-5353-4f83-91b4-57725b0c922b" x="370" y="41" width="185" height="20"/>
<textElement/>
<text><![CDATA[amount]]></text>
</staticText>
</band>
</groupHeader>
</group>
<detail>
<band height="20">
<textField>
<reportElement uuid="5b325da6-7c56-4357-8808-911dad16ec53" x="0" y="0" width="185" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{Name}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="0bc06b28-7b8c-4af9-997a-714d1599def1" x="185" y="0" width="185" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{email}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="e5504bb9-c3c0-4135-94c6-7ea935f97cb6" x="370" y="0" width="185" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{amount}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
Let me depict a situation: I have a report A and subreports B and C. A uses B and B uses C. Default value of SUBREPORT_DIR in A is $P{CUSTOM_SUBREPORT_DIR}. In A.jrxml I see:
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA[$P{CUSTOM_SUBREPORT_DIR}]]></defaultValueExpression>
</parameter>
<parameter name="CUSTOM_SUBREPORT_DIR" class="java.lang.String">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
I also need a proper value of SUBREPORT_DIR in B so I passed it using iReport (Subreport properties/Parameters) so in A.jrxml I have:
<subreportParameter name="SUBREPORT_DIR">
<subreportParameterExpression><![CDATA[$P{SUBREPORT_DIR}]]></subreportParameterExpression>
</subreportParameter>
And when I'm trying to generate report A I get net.sf.jasperreports.engine.JRException: Incompatible java.lang.Integer value assigned to parameter SUBREPORT_DIR in the B dataset.
I'm sure that $P{SUBREPORT_DIR} isn't an integer and type of SUBREPORT_DIR parameter in B subreport is String. All reports I made using iReport 4.0.2.
You can try the following (I do it in this way and it works):
Define the parameters in report A:
<parameter name="SUBREPORT_B_DIR" class="java.lang.String" isForPrompting="false" />
<parameter name="SUBREPORT_C_DIR" class="java.lang.String" isForPrompting="false" />
Define subreport B in report A. Here I use DataSource for report B from parameter. Also I send a parameter to subreport B with the subreport C directory and another parameter with DataSource for report C.
<subreport>
<reportElement x="0" y="16" width="583" height="10" />
<subreportParameter name="SUBREPORT_C_DIR">
<subreportParameterExpression><![CDATA[$P{SUBREPORT_C_DIR}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="SubReportCDataSource">
<subreportParameterExpression><![CDATA[$P{SubReportCDataSource}]]></subreportParameterExpression>
</subreportParameter>
<dataSourceExpression><![CDATA[$P{SubReportBDataSource}]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_B_DIR} + "B.jasper"]]></subreportExpression>
</subreport>
Finally, in subreport B, define subreport C:
<subreport>
<reportElement x="0" y="16" width="583" height="10" />
<dataSourceExpression><![CDATA[$P{SubReportCDataSource}]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_C_DIR} + "C.jasper"]]></subreportExpression>
</subreport>