IReport4.8.0を使用しています。データセットを作成し、それを表とグラフに使用すると、すべてが正常に機能します。
ここで、ユーザーが都市の名前を挿入できるように、文字列パラメーターを追加します。
そこで、データセット内に新しい文字列パラメーターを追加し、それをページヘッダーにドラッグしました。また、データセットクエリを更新して、パラメータから値を受け取るようにしました。
SELECT
COUNT(leads.`status`) AS Number_Of_Status,
leads.`status` AS leads_status,
leads.`primary_address_city` AS leads_primary_address_city
FROM
`leads` leads
WHERE
leads.`primary_address_city` = $P{city_to_choose}
GROUP BY
leads.`status`
しかし、「プレビュー」を押したときに得られるのは、「パラメーターが見つかりません:city_to_choose」だけです。何を見逃しましたか?
レポートのxmlコードは次のとおりです。
<?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="report44" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="94efea4a-2952-4cb2-9d88-3f853af2a264">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<style name="table">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="table_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
<conditionalStyle>
<conditionExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()%2==0)]]></conditionExpression>
<style backcolor="#EFF7FF"/>
</conditionalStyle>
</style>
<style name="table 1">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="table 1_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 1_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 1_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
<conditionalStyle>
<conditionExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()%2==0)]]></conditionExpression>
<style backcolor="#EFF7FF"/>
</conditionalStyle>
</style>
<style name="table 2">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="table 2_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 2_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 2_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
<conditionalStyle>
<conditionExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()%2==0)]]></conditionExpression>
<style backcolor="#EFF7FF"/>
</conditionalStyle>
</style>
<style name="table 3">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="table 3_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 3_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 3_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
<conditionalStyle>
<conditionExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()%2==0)]]></conditionExpression>
<style backcolor="#EFF7FF"/>
</conditionalStyle>
</style>
<style name="table 4">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="table 4_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 4_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 4_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
<conditionalStyle>
<conditionExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()%2==0)]]></conditionExpression>
<style backcolor="#EFF7FF"/>
</conditionalStyle>
</style>
<subDataset name="New Dataset 1" uuid="281c076f-1c95-4550-aa87-5ee8f14654a6">
<parameter name="city_to_choose" class="java.lang.String">
<defaultValueExpression><![CDATA["Cupertino"]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[SELECT
COUNT(leads.`status`) AS Number_Of_Status,
leads.`status` AS leads_status,
leads.`primary_address_city` AS leads_primary_address_city
FROM
`leads` leads
WHERE
leads.`primary_address_city` = $P{city_to_choose}
GROUP BY
leads.`status`]]>
</queryString>
<field name="Number_Of_Status" class="java.lang.Long"/>
<field name="leads_status" class="java.lang.String"/>
<field name="leads_primary_address_city" class="java.lang.String"/>
<group name="Number_Of_Status">
<groupExpression><![CDATA[$F{Number_Of_Status}]]></groupExpression>
</group>
</subDataset>
<queryString>
<![CDATA[select 1 as dummy_field]]>
</queryString>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="50"/>
</title>
<pageHeader>
<band height="50">
<textField pattern="">
<reportElement uuid="ba67dc80-1d24-4900-8bae-95562947f757" x="114" y="17" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$P{city_to_choose}]]></textFieldExpression>
</textField>
</band>
</pageHeader>
<detail>
<band height="238" splitType="Stretch">
<componentElement>
<reportElement uuid="2692dbf7-e921-4098-a140-9ed1fc602281" key="table 4" style="table 4" x="0" y="0" width="555" height="190"/>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="New Dataset 1" uuid="64281428-2692-42a5-b3c0-357fd1662cb0">
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
<jr:column width="90" uuid="13b614d9-0f9f-423e-8fca-4a5f2bce1dfb">
<jr:tableHeader style="table 4_TH" height="30"/>
<jr:tableFooter style="table 4_TH" height="30"/>
<jr:columnHeader style="table 4_CH" height="30">
<staticText>
<reportElement uuid="e89c0625-fb19-4b97-9bbc-80111f5d5055" x="0" y="0" width="90" height="30"/>
<textElement/>
<text><![CDATA[Lead Status]]></text>
</staticText>
</jr:columnHeader>
<jr:columnFooter style="table 4_CH" height="30"/>
<jr:detailCell style="table 4_TD" height="20">
<textField>
<reportElement uuid="f05e13d6-93ba-42df-ab80-65f156bec0e5" x="0" y="0" width="90" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{leads_status}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90" uuid="769cd50d-72b1-42f9-9c21-6c9de4a257df">
<jr:tableHeader style="table 4_TH" height="30"/>
<jr:tableFooter style="table 4_TH" height="30"/>
<jr:columnHeader style="table 4_CH" height="30">
<staticText>
<reportElement uuid="68e27cb2-6b6d-436a-8b28-a495df0a2243" x="0" y="0" width="90" height="30"/>
<textElement/>
<text><![CDATA[Status Count]]></text>
</staticText>
</jr:columnHeader>
<jr:columnFooter style="table 4_CH" height="30"/>
<jr:detailCell style="table 4_TD" height="20">
<textField>
<reportElement uuid="6dcea81c-8d64-4e87-8c91-c958dba68005" x="0" y="0" width="90" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{Number_Of_Status}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
<pageFooter>
<band splitType="Stretch"/>
</pageFooter>
<summary>
<band height="232" splitType="Stretch">
<pie3DChart>
<chart>
<reportElement uuid="0838f48f-8053-4f24-b429-74124641b223" x="0" y="0" width="555" height="232"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<pieDataset>
<dataset>
<datasetRun subDataset="New Dataset 1" uuid="88beae40-88ab-4f36-9f8a-9206883f0a05"/>
</dataset>
<keyExpression><![CDATA[$F{leads_status}]]></keyExpression>
<valueExpression><![CDATA[$F{Number_Of_Status}]]></valueExpression>
</pieDataset>
<pie3DPlot>
<plot/>
<itemLabel/>
</pie3DPlot>
</pie3DChart>
</band>
</summary>