How to properly stretch with overflow for non-detail band [duplicate] - jasper-reports

This question already has answers here:
Stretch a row with data overflow while having multiple rows in a single band
(3 answers)
Closed 4 years ago.
I have fields in title and page header that have multiple lines. I want them to stretch vertically but the problem is the field below the stretched field is missing. I also grouped them using a frame.
The properties I set:
Position Type : Float
Stretch Type : Relative to Tallest Object
Stretch With Overflow : True
Please see below screen shot.

You can try these properties of text : -
For first field (Cashier Name) of title band use this properties :-
Position Type- Fix Relative to Top
Stretch Type- Relative to Band Height
Stretch With Overflow - true
For the second field (Date) set these properties
Position Type- Fix Relative to Bottom
Stretch Type- No stretch
Stretch With Overflow- false
In this report you can see the properties if you run the report with Sample HSQL database in ireport :-
<?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="ward utilization" pageWidth="300" pageHeight="300" orientation="Landscape" columnWidth="280" leftMargin="10" rightMargin="10" topMargin="10" bottomMargin="10" uuid="85476864-df43-454c-83dd-9c1b475ec223">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
<![CDATA[select * from orders]]>
</queryString>
<field name="ORDERID" class="java.lang.Integer"/>
<field name="CUSTOMERID" class="java.lang.String"/>
<field name="EMPLOYEEID" class="java.lang.Integer"/>
<field name="ORDERDATE" class="java.sql.Timestamp"/>
<field name="REQUIREDDATE" class="java.sql.Timestamp"/>
<field name="SHIPPEDDATE" class="java.sql.Timestamp"/>
<field name="SHIPVIA" class="java.lang.Integer"/>
<field name="FREIGHT" class="java.math.BigDecimal"/>
<field name="SHIPNAME" class="java.lang.String"/>
<field name="SHIPADDRESS" class="java.lang.String"/>
<field name="SHIPCITY" class="java.lang.String"/>
<field name="SHIPREGION" class="java.lang.String"/>
<field name="SHIPPOSTALCODE" class="java.lang.String"/>
<field name="SHIPCOUNTRY" class="java.lang.String"/>
<group name="bed"/>
<title>
<band height="42">
<textField isStretchWithOverflow="true">
<reportElement uuid="c438eefe-5415-409e-8e7c-c763a7305ae2" stretchType="RelativeToBandHeight" x="87" y="0" width="24" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{SHIPNAME}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="83c8a0d7-af5f-43ec-88dd-7d923a5b2a28" positionType="FixRelativeToBottom" x="87" y="21" width="24" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{SHIPCITY}]]></textFieldExpression>
</textField>
</band>
</title>

I see two possible solutions here.
based on tests reproducing your error, you can set the date field as float also and it will shift down as the previous label (cashier name) overflows. Unfortunately this is part of a solution because then the field date does not align with its label.
create a table and set those labels and fields as a table and let it handle the overflow naturally. I failed to test it without using a datasource but I'm sure you can pass it the current report's datasource and fetch the data you need from it and display that info on that table.
Let me know if it worked for you. Also, tell me what else did you try. I'm curious now :)
Good luck.

Stretch Type : Relative to Tallest Object make verttical size of any items as maximal from all items. In this case previous element overlaps next (missing) item.
This is not need. Set stretch type = "No stretch". "Stretch with overflow = true" is enough for correct display items. (imho)
Solution: Put each pair label:field into individual frame. In this case label-fields will display in the corresponding rows

Related

How to send parameters from master report to chart (Line graph) in Jasper?

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

How to adjust text field with stretch with overflow

I use iReport 4.5.1 (I know it's so so old but it's at work and I don't have authority to upgrade it).
Anyway, I have a text field with following value:
$F{field1} + " — " + $F{field2}
Both field1 and field 2 are of java.lang.String type.
Since neither field1 nor field2 has consistent length, I have checked the stretch with the overflow property as TRUE. But the problem is that when I have a long text for field2 the rest of it comes below field1 while I need it begin right below field2.
Actually, it appears like:
something for field1 — something very long
for field2
While I need it like:
something for field1 — something very long
for field2
and if I put $F{field1} in a separate text field, since it doesn't have a fixed length, sometimes an extra space appears after $F{field1} or if I set its stretch with overflow property as TRUE, $F{field1} appears in two lines, which I don't like it either.
Generally, I need $F{field1} appear in one line with only one space after that and $F{field2} to split in two lines, if its length is too long, and appear as I described above.
Is there any way to do that?
Here's 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="adjust_textField" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<parameter name="parameter1" class="java.lang.Integer"/>
<queryString>
<![CDATA[SELECT code, name FROM test_co1 WHERE id = $P{parameter1}]]>
</queryString>
<field name="code" class="java.lang.String"/>
<field name="name" class="java.lang.String"/>
<detail>
<band height="125" splitType="Stretch">
<textField isStretchWithOverflow="true">
<reportElement positionType="Float" x="41" y="66" width="270" height="20"/>
<textElement verticalAlignment="Bottom">
<font fontName="Gill Sans MT" size="12" isBold="true"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{code} + " — " + $F{name}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
Which reads data from the following table:
CREATE TABLE public.test_co1 (
id INTEGER,
code TEXT,
name TEXT
) ;
/* Data for the 'public.test_co1' table (Records 1 - 54) */
INSERT INTO public.test_co1 ("id", "code", "name")
VALUES
(1, E'J', E'WELDING & CUTTING'),
(2, E'L', E'CONFINED SPACES'),
(6, E'N', E'COMPRESSED GAS/FUEL CYLINDERS'),
(15, E'W18', E'java code to iReportWEAPON SAFETY FOR PROP. MASTERS'),
(45, E'GD$', E'java code to iReportGENERAL SAFETY TRAINING/INJURY & ILLNESS PREVENTION PROGRAM'),
(49, E'GD$', E'java code to iReportENVIRONMENTAL SAFETY');
When you enter 45 as the parameter value, it displays it as
GD$ — java code to iReportGENERAL SAFETY
TRAINING/INJURY & ILLNESS PREVENTION
PROGRAM
while I need it as :
GD$ — java code to iReportGENERAL SAFETY
TRAINING/INJURY & ILLNESS PREVENTION
PROGRAM
Try something like this:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.0.final using JasperReports Library version 6.3.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="adjust_textField" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="f5fbc25f-d746-4a3c-bb20-80389233ba42">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<parameter name="parameter1" class="java.lang.Integer"/>
<queryString>
<![CDATA[SELECT id, code, name FROM test_co1
WHERE id = $P{parameter1}]]>
</queryString>
<field name="id" class="java.lang.Integer"/>
<field name="code" class="java.lang.String"/>
<field name="name" class="java.lang.String"/>
<detail>
<band height="125" splitType="Stretch">
<textField isStretchWithOverflow="true">
<reportElement stretchType="RelativeToTallestObject" x="0" y="0" width="100" height="30" uuid="b40f6b54-cdd8-4bed-8a3f-96808e8eeecb"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$F{code} + " — "]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement x="100" y="0" width="180" height="30" uuid="db6850d8-c213-4544-8bae-cf515ae7484e"/>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
I haven't tested it, but the idea is to create two fields that will stretch in height with each other. The first field is right-aligned and the second field is left-aligned.
This was written using JasperReports 6.3, so the code might not work in an older version. The approach, though, is likely correct.

Pagination in bar chart with series

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.

Chart with multiple series on each row

I'm trying to do an iReport chart with this table
name|totalcalls|handled|abandoned|rejected
customerservice|300|100|100|100
itsupport|500|300|100|100
The idea is that there should be 2 charts in this case, that was easily solved by putting the chart into the details row.
But I cannot figure out how to make iReport treat the 3 last columns (handled, abandoned, rejected) as different series.
Ideally I want to do a stacked barchart that looks like this:
customerservice|-100-|-100-|-100-
itsupport|---300---|-100-|100
I have no clue how to make this work.
To achieve this you can use a stacked bar chart. Open iReport and drag and drop the chart element from the palette to the report designer. In the wizard select Stacked Bar, then click Finish.
Right click on the chart and select Chart Data > Details:
click Add, enter Series Expression: "Handled", Category Expression: $F{name}, Value Expression: $F{handled}, click Ok
Add, Series Expression: "Abandoned", Category Expression: $F{name}, Value Expression: $F{abandoned}, Ok
Add, Series Expression: "Rejected", Category Expression: $F{name}, Value Expression: $F{rejected}, Ok
Then click Close. Now select the chart object in the report designer and change in the properties panel Orientation to horizontal.
I put the chart into the summary band holding both rows of data in a single chart. You can apply the same settings for the chart being configured in the detail band for a similar output if required.
I also attach the JRXML for further reference:
<?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="report7" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="42d0d6ab-85f6-496b-8e61-c3d7588cfd8e">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
<![CDATA[select 'customerservice' as name, 300 as totalcalls, 100 as handled, 100 as abandoned, 100 as rejected
union select 'itsupport', 500, 300, 100, 100]]>
</queryString>
<field name="name" class="java.lang.String"/>
<field name="totalcalls" class="java.lang.Long"/>
<field name="handled" class="java.lang.Long"/>
<field name="abandoned" class="java.lang.Long"/>
<field name="rejected" class="java.lang.Long"/>
<summary>
<band height="92">
<stackedBarChart>
<chart>
<reportElement uuid="f0bfeda6-003e-40c0-8d75-0c61bc620978" x="0" y="0" width="555" height="92"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<categoryDataset>
<categorySeries>
<seriesExpression><![CDATA["Handled"]]></seriesExpression>
<categoryExpression><![CDATA[$F{name}]]></categoryExpression>
<valueExpression><![CDATA[$F{handled}]]></valueExpression>
</categorySeries>
<categorySeries>
<seriesExpression><![CDATA["Abandoned"]]></seriesExpression>
<categoryExpression><![CDATA[$F{name}]]></categoryExpression>
<valueExpression><![CDATA[$F{abandoned}]]></valueExpression>
</categorySeries>
<categorySeries>
<seriesExpression><![CDATA["Rejected"]]></seriesExpression>
<categoryExpression><![CDATA[$F{name}]]></categoryExpression>
<valueExpression><![CDATA[$F{rejected}]]></valueExpression>
</categorySeries>
</categoryDataset>
<barPlot>
<plot orientation="Horizontal"/>
<itemLabel/>
</barPlot>
</stackedBarChart>
</band>
</summary>
</jasperReport>

How can I pass sub-report value to main-report?

Here's the relation table
StudentName
Course
Marks
Peter
Bio
65
Peter
Chem
70
Peter
Music
80
David
Chem
50
How can I make something like the followings
Peter Total : 215
Subject : Bio - 65
Subject : Chem - 70
Subject : Music - 80
Peter Total : 50
Subject : Chem - 50
I would not use a subreport for this as this can be achieved in a simpler way: You can utilize Report groups and variables to achieve this. Make sure that the data is sorted accordingly to the output.
Preparation
Create a report group based on StudentName. Right Click in iReport in the report inspector on the report and select Add Report group. Follow the wizard, give it a name (e.g. Student), select field StudentName as group expression, add header but no footer.
Create a variable that holds the total for a student. Right Click in iReport in the report inspector on Variables and select Add Variable. In the properties panel configure as follows: Name: totalMarkByStudent, Variable Class: java.lang.Long, Calculation: Sum, Reset Type: Group, Reset Group: Student, Variable Expression: $F{Marks}. Leave the rest to its default values.
Report Design
Drag and drop the Field StudentName from the report inspector into the report designer into the Student group header band. There will be a popup asking what kind of value shall be displayed, select The field value and click Ok.
Drag and drop the Variable totalMarksByStudent from the report inspector into the report designer into the Student group header band. Click on the text field and modify following settings in the properties panel:
Width: 200 (to allow more space)
Text field expression: "Total : " + $V{totalMarkByStudent}
Expression Class: java.lang.String
Evaluation Time: Group (meaning that the value gets evaluated once the processing of the group is finished)
Evaluation Group: Student
Drag and drop the fields Course and Marks from the report inspector into the detail band in the report designer. Right click on the course field and select Edit Expression. CHange the expression to "Subject : " + $F{Course} and click on Apply.
With this configuration you achieve a report output as in the image below.
For further reference here the complete JRXML using report group and variable:
<?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="report3" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="0dfbb9b2-a9ce-4447-beee-37d653140dd1">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
<![CDATA[select * from (
Select 'Peter' as StudentName, 'Bio' as Course, 65 as Marks
union select 'Peter', 'Chem', 70
union select 'Peter', 'Music', 80
union select 'David', 'Chem', 50
) tbl
order by StudentName, Course]]>
</queryString>
<field name="StudentName" class="java.lang.String"/>
<field name="Course" class="java.lang.String"/>
<field name="Marks" class="java.lang.Long"/>
<variable name="totalMarkByStudent" class="java.lang.Long" resetType="Group" resetGroup="Student" calculation="Sum">
<variableExpression><![CDATA[$F{Marks}]]></variableExpression>
</variable>
<group name="Student">
<groupExpression><![CDATA[$F{StudentName}]]></groupExpression>
<groupHeader>
<band height="50">
<textField>
<reportElement uuid="ea996b6c-d41d-47bb-bef1-5df580b5c161" x="0" y="30" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{StudentName}]]></textFieldExpression>
</textField>
<textField evaluationTime="Group" evaluationGroup="Student">
<reportElement uuid="8ddc9b5b-9c57-4fce-8ed0-587c6b54143c" x="180" y="30" width="200" height="20"/>
<textElement/>
<textFieldExpression><![CDATA["Total : " + $V{totalMarkByStudent}]]></textFieldExpression>
</textField>
</band>
</groupHeader>
</group>
<detail>
<band height="20">
<textField>
<reportElement uuid="f67b4e51-4da6-4758-b3d3-bd75de70c0f7" x="0" y="0" width="180" height="20"/>
<textElement/>
<textFieldExpression><![CDATA["Subject : " + $F{Course}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="ea82c278-d2f3-4467-bf5d-8dab9ff99ae3" x="180" y="0" width="277" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{Marks}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
If you use a subreport instead
I assume that the subreport is paraemterized with the student id shows the data for a given student. The main report shows the field StudentName and the subreport in the detail panel.
Create a variable total in the subreport that calculates the total for the student.
Create a variable totalByStudent in the main report with calculation type set to System.
Click on the subreport and in the properties panel click on Return values. Click Add and select: Subreport variable: total, Local Destination Variable: totalByStudent, rest leave to default. Click on Ok.
Drag and drop the variable totalByStudent into the detail band. Select it and in the Properties panel set Evaluation time to Band. The output will be the same as shown above.
I recommend to use the approach with report group and variable as it reduces the complexity of the report, as well as performance for this way would be better.