Jump to content
Changes to the Jaspersoft community edition download ×

creating two charts in one report with two different queries in jasper reports


kiran_3

Recommended Posts

i am trying to do a report which contains two charts in one report with two different queries which take same parameters. this is my jrxml file main report and sub-report respectively . when i preview my report first chat is coming while second chart is not coming,i am using jaspersoft studio professional in ubuntu 14, did i miss anything?

<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.0.1.final using JasperReports Library version 6.0.0  --><!-- 2015-02-20T17:34:56 --><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="virtual_number" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="2c7c66ad-110f-4423-b087-53c5b107339b">    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="mysql_db"/>    <parameter name="startDate" class="java.util.Date"/>    <parameter name="endDate" class="java.util.Date"/>    <queryString>        <![CDATA[select date(vnc.created) as 'date',sum(if(vnc.status='not_answered', 1,0)) as 'no answer',         sum(if(vnc.status='answered', 1,0)) as 'Answered' ,sum(if(vnc.status is null, 1,0)) as 'nothing' from virtual_number_contacted as vnc where vnc.created between $P{startDate}         AND $P{endDate} group by status]]>    </queryString>    <field name="date" class="java.lang.String"/>    <field name="no answer" class="java.lang.Long"/>    <field name="Answered" class="java.lang.Long"/>    <field name="nothing" class="java.lang.Long"/>    <background>        <band splitType="Stretch"/>    </background>    <title>        <band height="79" splitType="Stretch"/>    </title>    <summary>        <band height="506" splitType="Stretch">            <lineChart>                <chart evaluationTime="Report">                    <reportElement x="40" y="11" width="660" height="200" uuid="4bd5812c-6956-415a-ace6-8d16bb00ba6e"/>                    <chartTitle/>                    <chartSubtitle/>                    <chartLegend/>                </chart>                <categoryDataset>                    <categorySeries>                        <seriesExpression><![CDATA["answered"]]></seriesExpression>                        <categoryExpression><![CDATA[$F{date}]]></categoryExpression>                        <valueExpression><![CDATA[$F{Answered}]]></valueExpression>                    </categorySeries>                    <categorySeries>                        <seriesExpression><![CDATA["not-answered"]]></seriesExpression>                        <categoryExpression><![CDATA[$F{date}]]></categoryExpression>                        <valueExpression><![CDATA[$F{no answer}]]></valueExpression>                    </categorySeries>                    <categorySeries>                        <seriesExpression><![CDATA["nothing"]]></seriesExpression>                        <categoryExpression><![CDATA[$F{date}]]></categoryExpression>                        <valueExpression><![CDATA[$F{nothing}]]></valueExpression>                    </categorySeries>                </categoryDataset>                <linePlot>                    <plot/>                    <categoryAxisFormat>                        <axisFormat/>                    </categoryAxisFormat>                    <valueAxisFormat>                        <axisFormat/>                    </valueAxisFormat>                </linePlot>            </lineChart>            <subreport>                <reportElement x="3" y="210" width="750" height="200" uuid="230e6022-d9f9-4bcf-a75a-b5f42f1c5b05"/>                <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>                <subreportExpression><![CDATA["callduation.jasper"]]></subreportExpression>            </subreport>        </band>    </summary></jasperReport>[/code]

here is my sub-report

 

<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="callduation" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="62f38574-322f-415e-a109-1595b0458790">    <parameter name="startDate" class="java.util.Date"/>    <parameter name="endDate" class="java.util.Date"/>    <queryString>        <![CDATA[select vmc.created as 'date', sum(if(vmc.status='OPEN', 1,0)) as 'no answer' from need as vmc where vmc.created between $P{startDate} AND $P{endDate}]]>    </queryString>    <field name="date" class="java.sql.Timestamp"/>    <field name="call_duration" class="java.lang.String">        <fieldDescription><![CDATA[]]></fieldDescription>    </field>    <background>        <band splitType="Stretch"/>    </background>    <detail>        <band height="125" splitType="Stretch"/>    </detail>    <summary>        <band height="237" splitType="Stretch">            <lineChart>                <chart evaluationTime="Report">                    <reportElement x="-20" y="37" width="578" height="200" uuid="8ea113c9-49b3-49de-beb0-13ca1a35ac3b"/>                    <chartTitle/>                    <chartSubtitle/>                    <chartLegend/>                </chart>                <categoryDataset>                    <categorySeries>                        <seriesExpression><![CDATA["SERIES 1"]]></seriesExpression>                        <categoryExpression><![CDATA[$F{date}]]></categoryExpression>                        <valueExpression><![CDATA[$F{call_duration}]]></valueExpression>                    </categorySeries>                </categoryDataset>                <linePlot>                    <plot/>                    <categoryAxisFormat>                        <axisFormat/>                    </categoryAxisFormat>                    <valueAxisFormat>                        <axisFormat/>                    </valueAxisFormat>                </linePlot>            </lineChart>        </band>    </summary></jasperReport>[/code]
Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hello Kiran,

 

I believe you need to specify $P{REPORT_PARAMETERS_MAP} parameter as a value of parametersMapExpression property for subreport. As of now it looks like startDate and endDate parameters in subreport have null values and your subreport query returns no data for the chart.

 

Also, a simple way to display two charts in a report would be to create a dataset and use it for the second chart instead of creating a subreport.

 

- Stas

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...