如何在Jasper中将参数从主报告发送到图表(折线图)?

时间:2019-04-18 11:50:53

标签: charts jasper-reports

我正在生成具有表格和折线图的报告。 主报告数据集返回8条记录。因此,我需要8页,每页显示每个记录的数据。我已经将字段从主数据集映射到表和折线图的数据集。

该表以正确的参数值完美显示8次。 但是,折线图总是显示最后一个参数值的数据。

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="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:表格和图形都在详细信息部分中。 另外,我正在eclipse中尝试-报表设计器插件

1 个答案:

答案 0 :(得分:0)

最后,我设法解决了这个问题。 问题在于图表表达的评估时间。

错误地将其设置为“报告”。我将其更改为“现在”。

替换了此
<chart evaluationTime="Report">

具有以下
<chart evaluationTime="Now">

evaluationTime -确定何时评估图表的表达式。值可以是立即,报告,页面,列,组,带。默认值为Now