Jasper为每个系列变量创建一个条形图

时间:2018-08-17 18:22:27

标签: charts jasper-reports

我正在创建一个报告,该报告需要多个条形图以根据用户角色跟踪哪个用户将转到哪个页面。

每个角色都是自己的系列,但是当我运行报表时,我获得了正确的数据,但是每个系列都在制作自己的图表

即我有两个搜索页面A和B

公共用户访问A 5次,两次B 管理员进入B 2次和B 9次

该报告将创建4个报告:public / A,public / B,admin / A,admin / B

但是,图表在A的同一图表上应该是公开的,并且在B的同一图表上应该是管理员的

任何想法

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1  -->
<!-- 2018-08-17T13:07:36 -->
<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="DEL_sys_usg_rpt_bar" pageWidth="576" pageHeight="792" whenNoDataType="AllSectionsNoDetail" columnWidth="536" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isSummaryWithPageHeaderAndFooter="true" uuid="c90df0e9-ca70-4aa8-88ab-3cc66cad2ade">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="New Data Adapter (2)"/>
    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
    <property name="com.jaspersoft.studio.unit." value="inch"/>
    <property name="net.sf.jasperreports.print.create.bookmarks" value="false"/>
    <parameter name="START_DATE" class="java.util.Date"/>
    <parameter name="END_DATE" class="java.util.Date"/>
    <parameter name="START_DATE_RPT" class="java.lang.String"/>
    <parameter name="END_DATE_RPT" class="java.lang.String"/>
    <parameter name="SCREENS" class="java.util.Collection"/>
    <parameter name="Q1START" class="java.util.Date"/>
    <parameter name="Q1END" class="java.util.Date"/>
    <parameter name="Q2START" class="java.util.Date"/>
    <parameter name="Q2END" class="java.util.Date"/>
    <parameter name="Q3START" class="java.util.Date"/>
    <parameter name="Q3END" class="java.util.Date"/>
    <parameter name="Q4START" class="java.util.Date"/>
    <parameter name="Q4END" class="java.util.Date"/>
    <queryString>
        <![CDATA[SELECT
t.qtr,
t.url_txt as url_txt,
sum(t.role0) as role0_page,
sum(t.role1) as role1_page,
sum(t.role2) as role2_page,
sum(t.role3) as role3_page,
sum(t.role4) as role4_page,
t.user_role_txt as user_role_txt
from 
(
                SELECT 
               $P{Q1START} as qtr,
                url_txt,
                user_role_txt,
                CASE when user_role_txt = 'Role0'  then 1 else 0 end as role0,
                CASE when user_role_txt = 'Role1' then 1 else 0 end as role1,
                CASE when user_role_txt = 'Role2' then 1 else 0 end as role2,
                CASE when user_role_txt = 'Role3'  then 1 else 0 end as role3,
                CASE when user_role_txt = 'Role4'  then 1 else 0 end as role4
                from table
                where acs_ts::date >= $P{Q1START}
                AND acs_ts::date <= $P{Q1END}     
                 AND $X{IN,url_txt,SCREENS}
UNION ALL
                SELECT 
                $P{Q2START} as qtr,
                url_txt,
                user_role_txt,
                                   CASE when user_role_txt = 'Role0'  then 1 else 0 end as role0,
                CASE when user_role_txt = 'Role1' then 1 else 0 end as role1,
                CASE when user_role_txt = 'Role2' then 1 else 0 end as role2,
                CASE when user_role_txt = 'Role3'  then 1 else 0 end as role3,
                CASE when user_role_txt = 'Role4'  then 1 else 0 end as role4                    from table
                where acs_ts::date >= $P{Q2START}
                AND acs_ts::date <= $P{Q2END}     
                 AND $X{IN,url_txt,SCREENS}
UNION ALL
                SELECT 
                $P{Q3START} as qtr,
                url_txt,
                user_role_txt,
                                   CASE when user_role_txt = 'Role0'  then 1 else 0 end as role0,
                CASE when user_role_txt = 'Role1' then 1 else 0 end as role1,
                CASE when user_role_txt = 'Role2' then 1 else 0 end as role2,
                CASE when user_role_txt = 'Role3'  then 1 else 0 end as role3,
                CASE when user_role_txt = 'Role4'  then 1 else 0 end as role4                    from table
                where acs_ts::date >= $P{Q3START}
                AND acs_ts::date <= $P{Q3END}     
                 AND $X{IN,url_txt,SCREENS}
UNION ALL
                SELECT 
                $P{Q4START} as qtr,
                url_txt,
                user_role_txt,
                                   CASE when user_role_txt = 'Role0'  then 1 else 0 end as role0,
                CASE when user_role_txt = 'Role1' then 1 else 0 end as role1,
                CASE when user_role_txt = 'Role2' then 1 else 0 end as role2,
                CASE when user_role_txt = 'Role3'  then 1 else 0 end as role3,
                CASE when user_role_txt = 'Role4'  then 1 else 0 end as role4                    from table
                where acs_ts::date >= $P{Q4START}
                AND acs_ts::date <= $P{Q4END}     
                 AND $X{IN,url_txt,SCREENS}
) as t
group by t.qtr, t.url_txt,t.user_role_txt]]>
    </queryString>
    <field name="url_txt" class="java.lang.String"/>
    <field name="role0_page" class="java.lang.Integer"/>
    <field name="role1_page" class="java.lang.Integer"/>
    <field name="role2_page" class="java.lang.Integer"/>
    <field name="role3_page" class="java.lang.Integer"/>
    <field name="role4_page" class="java.lang.Integer"/>
    <field name="user_role_txt" class="java.lang.String"/>
    <field name="qtr" class="java.util.Date"/>
    <group name="Group1" keepTogether="true">
        <groupExpression><![CDATA[$F{url_txt}]]></groupExpression>
    </group>
    <pageHeader>
        <band height="98" splitType="Stretch">
            <staticText>
                <reportElement key="t_4" mode="Opaque" x="130" y="-1" width="320" height="15" isRemoveLineWhenBlank="true" forecolor="#000000" backcolor="#FFFFFF" uuid="70d07b08-a98f-462f-912c-86e8ca3cffa5">
                    <property name="net.sf.jasperreports.export.pdf.tag.h1" value="full"/>
                    <property name="com.jaspersoft.studio.unit.x" value="pixel"/>
                </reportElement>
                <box>
                    <topPen lineWidth="0.0" lineColor="#000000"/>
                    <leftPen lineWidth="0.0" lineColor="#000000"/>
                    <bottomPen lineWidth="0.0" lineColor="#000000"/>
                    <rightPen lineWidth="0.0" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Top">
                    <font fontName="Arial" size="12" isBold="true"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <text><![CDATA[DEL Report]]></text>
            </staticText>
            <textField pattern="([GENERAL])" isBlankWhenNull="true">
                <reportElement key="COMPUTE_5" mode="Opaque" x="140" y="15" width="300" height="15" forecolor="#000000" backcolor="#FFFFFF" uuid="fa243ebd-82b3-426a-8693-995a1d029d8c">
                    <property name="net.sf.jasperreports.export.pdf.tag.h2"/>
                    <property name="net.sf.jasperreports.export.pdf.tag.h1" value="full"/>
                </reportElement>
                <box>
                    <topPen lineWidth="0.0" lineColor="#000000"/>
                    <leftPen lineWidth="0.0" lineColor="#000000"/>
                    <bottomPen lineWidth="0.0" lineColor="#000000"/>
                    <rightPen lineWidth="0.0" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Top">
                    <font fontName="Arial" size="12" isBold="true"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <textFieldExpression><![CDATA["Data Element Library Usage Report"]]></textFieldExpression>
            </textField>
            <textField pattern="" isBlankWhenNull="true">
                <reportElement key="DATE_1" mode="Opaque" x="430" y="0" width="102" height="12" forecolor="#000000" backcolor="#FFFFFF" uuid="8c30e5fd-4921-4b61-a07d-fec225f73dca">
                    <property name="net.sf.jasperreports.export.pdf.tag.h2" value="full"/>
                    <property name="net.sf.jasperreports.export.pdf.tag.h3"/>
                </reportElement>
                <box>
                    <topPen lineWidth="0.0" lineColor="#000000"/>
                    <leftPen lineWidth="0.0" lineColor="#000000"/>
                    <bottomPen lineWidth="0.0" lineColor="#000000"/>
                    <rightPen lineWidth="0.0" lineColor="#000000"/>
                </box>
                <textElement verticalAlignment="Top">
                    <font fontName="Arial" size="8"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <textFieldExpression><![CDATA["Run Date:  " + new SimpleDateFormat("MM/dd/yyyy").format(new Date())]]></textFieldExpression>
            </textField>
            <textField pattern="" isBlankWhenNull="true">
                <reportElement key="PAGE_1" mode="Opaque" x="430" y="12" width="40" height="12" forecolor="#000000" backcolor="#FFFFFF" uuid="d3278171-f2e1-4241-b57f-5e4f3fc2ee09">
                    <property name="net.sf.jasperreports.export.pdf.tag.h2" value="start"/>
                    <property name="net.sf.jasperreports.export.pdf.tag.h3"/>
                </reportElement>
                <box>
                    <topPen lineWidth="0.0" lineColor="#000000"/>
                    <leftPen lineWidth="0.0" lineColor="#000000"/>
                    <bottomPen lineWidth="0.0" lineColor="#000000"/>
                    <rightPen lineWidth="0.0" lineColor="#000000"/>
                </box>
                <textElement verticalAlignment="Top">
                    <font fontName="Arial" size="8"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <textFieldExpression><![CDATA["Page " + $V{PAGE_NUMBER} + " of "]]></textFieldExpression>
            </textField>
            <textField evaluationTime="Report" pattern="" isBlankWhenNull="true">
                <reportElement key="PAGE_1" mode="Transparent" x="470" y="12" width="30" height="12" forecolor="#000000" backcolor="#FFFFFF" uuid="f12aa9ee-4dbb-4569-bad4-1994dcfc045c">
                    <property name="net.sf.jasperreports.export.pdf.tag.h3"/>
                    <property name="net.sf.jasperreports.export.pdf.tag.h2" value="end"/>
                </reportElement>
                <box>
                    <topPen lineWidth="0.0" lineColor="#000000"/>
                    <leftPen lineWidth="0.0" lineColor="#000000"/>
                    <bottomPen lineWidth="0.0" lineColor="#000000"/>
                    <rightPen lineWidth="0.0" lineColor="#000000"/>
                </box>
                <textElement verticalAlignment="Top">
                    <font fontName="Arial" size="8"/>
                    <paragraph lineSpacing="Single"/>
                </textElement>
                <textFieldExpression><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
            </textField>
            <image>
                <reportElement x="0" y="0" width="150" height="56" uuid="5c21389e-0147-4bab-8b2b-b2462883c4e4">
                    <property name="com.jaspersoft.studio.unit.width" value="pixel"/>
                    <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                </reportElement>
                <imageExpression><![CDATA[$P{CMSLOGO_DIR} + "CMS_logo.jpg"]]></imageExpression>
                <hyperlinkTooltipExpression><![CDATA["Centers for Medicare & Medicaid Services"]]></hyperlinkTooltipExpression>
            </image>
            <staticText>
                <reportElement x="0" y="70" width="280" height="12" uuid="9f93ebb5-6ca9-4f7f-be7c-d06093207859">
                    <property name="net.sf.jasperreports.export.pdf.tag.h3" value="start"/>
                    <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                </reportElement>
                <textElement verticalAlignment="Top">
                    <font fontName="Arial" isBold="false"/>
                </textElement>
                <text><![CDATA[Note: * indicates an empty value.]]></text>
            </staticText>
            <textField>
                <reportElement x="140" y="30" width="300" height="20" uuid="c2b0287c-ce1e-461c-aabb-1c6e28b0b30d"/>
                <textElement textAlignment="Center"/>
                <textFieldExpression><![CDATA["From "+$P{START_DATE_RPT}+" to "+$P{END_DATE_RPT}]]></textFieldExpression>
            </textField>
        </band>
    </pageHeader>
    <detail>
        <band height="285">
            <barChart>
                <chart isShowLegend="true">
                    <reportElement key="" isPrintRepeatedValues="false" x="0" y="19" width="480" height="245" uuid="55b46114-7361-48b7-8dac-5c40089efb33">
                        <property name="com.jaspersoft.studio.unit.y" value="inch"/>
                    </reportElement>
                    <chartTitle position="Top">
                        <titleExpression><![CDATA[$F{url_txt}]]></titleExpression>
                    </chartTitle>
                    <chartSubtitle/>
                    <chartLegend position="Right"/>
                </chart>
                <categoryDataset>
                    <dataset incrementType="Page"/>
                    <categorySeries>
                        <seriesExpression><![CDATA["Role0"]]></seriesExpression>
                        <categoryExpression><![CDATA[$F{qtr}]]></categoryExpression>
                        <valueExpression><![CDATA[$F{role0_page}]]></valueExpression>
                    </categorySeries>
                    <categorySeries>
                        <seriesExpression><![CDATA["Role1"]]></seriesExpression>
                        <categoryExpression><![CDATA[$F{qtr}]]></categoryExpression>
                        <valueExpression><![CDATA[$F{role1_page}]]></valueExpression>
                    </categorySeries>
                    <categorySeries>
                        <seriesExpression><![CDATA["Role2"]]></seriesExpression>
                        <categoryExpression><![CDATA[$F{qtr}]]></categoryExpression>
                        <valueExpression><![CDATA[$F{role2_page}]]></valueExpression>
                    </categorySeries>
                    <categorySeries>
                        <seriesExpression><![CDATA["Role3"]]></seriesExpression>
                        <categoryExpression><![CDATA[$F{qtr}]]></categoryExpression>
                        <valueExpression><![CDATA[$F{role3_page}]]></valueExpression>
                    </categorySeries>
                    <categorySeries>
                        <seriesExpression><![CDATA["Role4"]]></seriesExpression>
                        <categoryExpression><![CDATA[$F{qtr}]]></categoryExpression>
                        <valueExpression><![CDATA[$F{role4_page}]]></valueExpression>
                    </categorySeries>
                </categoryDataset>
                <barPlot>
                    <plot/>
                    <itemLabel/>
                    <categoryAxisLabelExpression><![CDATA["Quarter"]]></categoryAxisLabelExpression>
                    <categoryAxisFormat>
                        <axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/>
                    </categoryAxisFormat>
                    <valueAxisLabelExpression><![CDATA["Page Count"]]></valueAxisLabelExpression>
                    <valueAxisFormat>
                        <axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/>
                    </valueAxisFormat>
                </barPlot>
            </barChart>
        </band>
    </detail>
</jasperReport>

编辑:由于变量名称不同,我在同一张图表上获得了所有序列

0 个答案:

没有答案