Jump to content
We've recently updated our Privacy Statement, available here ×

Sub-report chart is not getting displayed in main report


qaautomation2

Recommended Posts

Hi,

I am facing an issue to pass data from main report to sub-report in JasperStudio. My sub-report contains charts and it complies and displays the data but same sub-report chart is missing in main report.
Below are the Json data, main report jrxml and sub-report ixml. Can someone please point me if I have missed something in report generation process.

Json Data:
===========
{
  "report": {
    "pie": [
      { 
        "Response": "2XX",
        "Count": 2000
      },
      { 
        "Response": "3XX",
        "Count": 120
      },
      { 
        "Response": "5XX",
        "Count": 20
      }
    ],
    "line_chart": [
      { 
        "application": "http",
        "field": "totalInLatency_sum",
        "timestamp": "1.55944008E12",
        "value": 16
      },
      { 
        "application": "http",
        "field": "totalInLatency_sum",
        "timestamp": "1.5594408E12",
        "value": 0
      },
      { 
        "application": "http",
        "field": "totalInLatency_sum",
        "timestamp": "1.55944152E12",
        "value": 0
      },
      { 
        "application": "http",
        "field": "totalInLatency_sum",
        "timestamp": "1.55944224E12",
        "value": 16
      },
      { 
        "application": "http",
        "field": "totalInLatency_sum",
        "timestamp": "1.55944296E12",
        "value": 16
      }
    ] 
  }     
}

Main report:
============

<?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="main" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="5d267a87-164b-4cd6-b76a-3bc62e2fb6c1">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="sub-report"/>
    <queryString language="json">
        <![CDATA[]]>
    </queryString>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch"/>
    </title>
    <detail>
        <band height="284" splitType="Stretch">
            <subreport>
                <reportElement x="160" y="30" width="200" height="200" uuid="288b0bd8-c52a-47a5-8af5-d05d1e00e659"/>
                <dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("report.pie")]]></dataSourceExpression>
                <subreportExpression><![CDATA["sub_chart.jasper"]]></subreportExpression>
            </subreport>
        </band>
    </detail>
</jasperReport>

Sub-report:
============

<?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="sub_chart" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="3fea9df4-65d2-4538-bbdb-89db4f3144d0">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="sub-report"/>
    <queryString language="json">
        <![CDATA[report.pie]]>
    </queryString>
    <field name="Response" class="java.lang.String">
        <property name="net.sf.jasperreports.json.field.expression" value="Response"/>
        <fieldDescription><![CDATA[Response]]></fieldDescription>
    </field>
    <field name="Count" class="java.lang.Integer">
        <property name="net.sf.jasperreports.json.field.expression" value="Count"/>
        <fieldDescription><![CDATA[Count]]></fieldDescription>
    </field>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch"/>
    </title>
    <summary>
        <band height="426" splitType="Stretch">
            <pieChart>
                <chart evaluationTime="Report">
                    <reportElement x="160" y="80" width="200" height="200" uuid="090c4417-61ea-4417-ab3a-6d25bab13eea"/>
                    <chartTitle/>
                    <chartSubtitle/>
                    <chartLegend/>
                </chart>
                <pieDataset>
                    <keyExpression><![CDATA[$F{Response}]]></keyExpression>
                    <valueExpression><![CDATA[$F{Count}]]></valueExpression>
                </pieDataset>
                <piePlot>
                    <plot/>
                    <itemLabel/>
                </piePlot>
            </pieChart>
        </band>
    </summary>
</jasperReport>

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Verify that the Subreport Expression is pointing to the correct/expected subreport. There are times (often due to copying and/or hand-editing existing JRXML files) where the Subreport Expression is still pointing to the subreport Jasper file of the original, Main report. I just ran into this case, myself.

Make sure that

<subreportExpression><![CDATA["The_Report.jasper"]]></subreportExpression>

isn't supposed to be something like

<subreportExpression><![CDATA["The_New_SubReport.jasper"]]></subreportExpression>

or contain the Subreport directory like

<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "The_New_SubReport.jasper"]]></subreportExpression>

Link to comment
Share on other sites

Are you sure, that your data-adapter is adjusted correctly? I just copied your json + jrxml to my workspace and renamed it to my needs and it works:

here the DefaultDataAdapter of MainReport:

<property name="com.jaspersoft.studio.data.defaultdataadapter" value="DatasourceJsonSubReportChart.xml"/>

 

and the same as  the DefaultDataAdapter of my SubReport:

<property name="com.jaspersoft.studio.data.defaultdataadapter" value="DatasourceJsonSubReportChart.xml"/>

Perhaps it's just a naming problem of your dataSource!??!

hth + regards

C-Box

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...