Jump to content

subdataset parameters


nanako

Recommended Posts

Thanks in advance for any help. I have been fighting with the proble for a log time.

 

 

I need to pass two parmaters two the subdataset and form a chart.

 

But generated chart is empty, the parmater is not passed to the query.

 

My template is as follows:

 

<subDataset name="history_perf">

<parameter name="startdate" class="java.sql.Timestamp"/>

<parameter name="enddate" class="java.sql.Timestamp"/>

<queryString>

<![CDATA[select perf_bps, order_date,exchange from daily_perf

where algorithm_name='GSAT_VWAP'

and order_date<=$P{startdate}

and order_date>=$P{enddate}

group by order_date

]]>

</queryString>

<field name="exchange" class="java.lang.String" />

<field name="perf_bps" class="java.lang.Double"/>

<field name="order_date" class="java.sql.Timestamp"/>

<group name="exchangeGroup">

<groupExpression>

<![CDATA[$F{exchange}]]>

</groupExpression>

</group>

</subDataset>

 

========================

<summary>

<band height="756">

<staticText>

<reportElement x="0" y="0" width="100" height="14" />

<textElement>

<font isBold="true"/>

</textElement>

<text>GSAT_VWAP</text>

</staticText>

<timeSeriesChart>

<chart evaluationTime="Report">

<reportElement mode="Opaque" x="0" y="14" width="750" height="175" />

</chart>

<timeSeriesDataset>

<dataset>

<datasetRun subDataset="history_perf">

<datasetParameter name="startdate">

<datasetParameterExpression>

<![CDATA[$F{order_date}]]>

</datasetParameterExpression>

</datasetParameter>

 

<datasetParameter name="enddate">

<datasetParameterExpression>

<![CDATA[$F{order_date}]]>

</datasetParameterExpression>

</datasetParameter>

 

</datasetRun>

</dataset>

<timeSeries>

<seriesExpression>$F{exchange}</seriesExpression>

<timePeriodExpression>$F{order_date}</timePeriodExpression>

<valueExpression>$F{perf_bps}</valueExpression>

<labelExpression></labelExpression>

</timeSeries>

</timeSeriesDataset>

<timeSeriesPlot> <plot/></timeSeriesPlot>

</timeSeriesChart>

</band>

</summary>

Link to comment
Share on other sites

  • Replies 8
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

nanako wrote:

and order_date<=$P{startdate}
and order_date>=$P{enddate}

 

I don't know what exactly are you trying to do, this this might be wrong. Isn't it supposed to be order_date >= $P{startdate} and order_date <= $P{enddate} (or order_date between $P{startdate} and $P{enddate} if you want to keep things simple)?

 

HTH,

Lucian

Link to comment
Share on other sites

thanks!

 

I have found the careless mistake by myself, and corrected it.

 

But the problem still exists.

 

And obviously the parameter values were not passed to the subdataset.

 

I have double check my template, cann't find anything wrong.

 

Thanks a lot if anyone could help

Link to comment
Share on other sites

nanako wrote:

And obviously the parameter values were not passed to the subdataset.

 

I'm not sure how is that so obvious.

 

I see that you have the chart in the summary band and you pass field values to the subdataset parameters (which is a little unusual). I suggest you to display the field values in a text field next to the chart (in the same band) so that actually you see the passed values.

 

Or if you have JR >= 1.2.8, add

Code:

log4j.logger.net.sf.jasperreports.engine.query.JRJdbcQueryExecuter=debug

to your log4j.properties (or the equivalent if you use another logging implementation) and JR will log the SQL query and its parameters.

 

Regards,

Lucian

Link to comment
Share on other sites

This case looks unusual because your chart will only use field values from the last record from the report's data source (given that there is at least one record in the data source, otherwise the fields will be null).

 

I'm afraid I can't tell you where to place your chart, since only you know what result you want to achieve.

 

Regards,

Lucian

Link to comment
Share on other sites

Thanks Lucian!!

 

The following is the complete template.

 

Actually there are 4 charts to be generated.

 

Every chart displays the peformance of a specific trading algorithm in the market.

 

I intend to designate the period of the data I wanna see the chart, that's why I have the startdate and enddate parameter. But the problem is these two parameters values cann't be passed to the subdataset query.

 

Currently I only assign parameters to subdataset1 for testing purpose. The chart can be generated but it didn't take the value of $P{enddate}. but the value of $P{orderdate}

===================================================

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">

<jasperReport leftMargin="0" name="TestReport">

<style name="parentStyle" isDefault="true" fontName="Arial" fontSize="11" forecolor="black"/>

<style name="ColumnHeadStyle" fontSize="14" isBold="true" fontName="Arial" forecolor="#ffffff" backcolor="#70DEDE"/>

<style name="ColumnStyle" fontSize="9" forecolor="red"/>

 

<subDataset name="history_perf">

<parameter name="startdate" class="java.util.Date"/>

<parameter name="enddate" class="java.util.Date"/>

<queryString>

<![CDATA[select perf_bps, order_date,exchange from daily_perf

where algorithm_name='GSAT_VWAP'

 

and order_date <=$P{enddate}

group by order_date

]]>

</queryString>

<field name="exchange" class="java.lang.String" />

<field name="perf_bps" class="java.lang.Double"/>

<field name="order_date" class="java.util.Date"/>

<group name="exchangeGroup">

<groupExpression>

<![CDATA[$F{exchange}]]>

</groupExpression>

</group>

</subDataset>

 

<subDataset name="history_perf2">

<queryString>

<![CDATA[select perf_bps, order_date,exchange from daily_perf

where algorithm_name='GSAT_Participate'

]]>

</queryString>

<field name="exchange" class="java.lang.String" />

<field name="perf_bps" class="java.lang.Double"/>

<field name="order_date" class="java.util.Date"/>

<group name="exchangeGroup">

<groupExpression>

<![CDATA[$F{exchange}]]>

</groupExpression>

</group>

</subDataset>

 

<subDataset name="history_perf3">

<queryString>

<![CDATA[select perf_bps, order_date,exchange from daily_perf

where algorithm_name in('HullVWAP','HullVWAPBeta')

]]>

</queryString>

<field name="exchange" class="java.lang.String" />

<field name="perf_bps" class="java.lang.Double"/>

<field name="order_date" class="java.util.Date"/>

<group name="exchangeGroup">

<groupExpression>

<![CDATA[$F{exchange}]]>

</groupExpression>

</group>

</subDataset>

 

<subDataset name="history_perf4">

<queryString>

<![CDATA[select perf_bps, order_date,exchange from daily_perf

where algorithm_name in('Participate','ParticipateBeta')

]]>

</queryString>

<field name="exchange" class="java.lang.String" />

<field name="perf_bps" class="java.lang.Double"/>

<field name="order_date" class="java.util.Date"/>

<group name="exchangeGroup">

<groupExpression>

<![CDATA[$F{exchange}]]>

</groupExpression>

</group>

</subDataset>

 

<parameter name="orderdate" class="java.sql.Timestamp"/>

<queryString>

<![CDATA[select algorithm_name,

exchange,

order_date,

order_count,

quantity,

value,

perf_bps,

perf_bps_stddev,

duration

from daily_perf

where order_date=$P{orderdate}

order by exchange]]>

</queryString>

 

<field name="algorithm_name" class="java.lang.String" />

<field name="exchange" class="java.lang.String" />

<field name="order_date" class="java.util.Date"/>

<field name="order_count" class="java.lang.Integer"/>

<field name="quantity" class="java.lang.Double"/>

<field name="value" class="java.lang.Double"/>

<field name="perf_bps" class="java.lang.Double"/>

<field name="perf_bps_stddev" class="java.lang.Double"/>

<field name="duration" class="java.lang.Double"/>

 

<group name="MarketGroup">

<groupExpression>

<![CDATA[$F{exchange}]]>

</groupExpression>

<groupHeader>

<band height="40">

<staticText>

<reportElement x="0" y="10" width="130" height="20"/>

<textElement>

<font isBold="true"/>

</textElement>

<text>History Performance in: </text>

</staticText>

<textField>

<reportElement x="130" y="10" width="40" height="20"/>

<textFieldExpression>$F{exchange}</textFieldExpression>

</textField>

</band>

</groupHeader>

</group>

 

 

<columnHeader>

<band height="14">

<staticText>

<reportElement mode="Opaque" forecolor="#ffffff" backcolor="#70DEDE" x="0" y="0" width="110" height="14"/>

<textElement isStyledText="true">

<font isBold="true"/>

</textElement>

<text><![CDATA[Algorithm]]></text>

</staticText>

 

<staticText>

<reportElement mode="Opaque" forecolor="#ffffff" backcolor="#70DEDE" x="110" y="0" width="60" height="14" />

<textElement>

<font isBold="true"/>

</textElement>

<text>Exchange</text>

</staticText>

 

<staticText>

<reportElement mode="Opaque" forecolor="#ffffff" backcolor="#70DEDE" x="170" y="0" width="79" height="14" />

<textElement>

<font isBold="true"/>

</textElement>

<text>Order Date</text>

</staticText>

<staticText>

<reportElement mode="Opaque" forecolor="#ffffff" backcolor="#70DEDE" x="249" y="0" width="60" height="14" />

<textElement>

<font isBold="true"/>

</textElement>

<text>Orders</text>

</staticText>

<staticText>

<reportElement mode="Opaque" forecolor="#ffffff" backcolor="#70DEDE" x="309" y="0" width="100" height="14" />

<textElement>

<font isBold="true"/>

</textElement>

<text>Shares</text>

</staticText>

<staticText>

<reportElement mode="Opaque" forecolor="#ffffff" backcolor="#70DEDE" x="409" y="0" width="120" height="14" />

<textElement>

<font isBold="true"/>

</textElement>

<text>Value(USD/mm)</text>

</staticText>

<staticText>

<reportElement mode="Opaque" forecolor="#ffffff" backcolor="#70DEDE" x="529" y="0" width="109" height="14" />

<textElement>

<font isBold="true"/>

</textElement>

<text>Performance(bps)</text>

</staticText>

<staticText>

<reportElement mode="Opaque" forecolor="#ffffff" backcolor="#70DEDE" x="638" y="0" width="110" height="14" />

<textElement>

<font isBold="true"/>

</textElement>

<text>Perf stddev(bps)</text>

</staticText>

<staticText>

<reportElement mode="Opaque" forecolor="#ffffff" backcolor="#70DEDE" x="748" y="0" width="80" height="14" />

<textElement>

<font isBold="true"/>

</textElement>

<text>Duration</text>

</staticText>

</band>

</columnHeader>

 

 

<detail>

<band height="14">

<textField>

<reportElement x="0" y="0" width="110" height="14"/>

<textFieldExpression class="java.lang.String">

<![CDATA[$F{algorithm_name}]]>

</textFieldExpression>

</textField>

<textField>

<reportElement x="110" y="0" width="50" height="14"/>

<textFieldExpression class="java.lang.String">

<![CDATA[$F{exchange}]]>

</textFieldExpression>

</textField>

<textField>

<reportElement x="170" y="0" width="79" height="14" />

<textFieldExpression class="java.util.Date">

<![CDATA[$F{order_date}]]>

</textFieldExpression>

</textField>

<textField>

<reportElement x="249" y="0" width="60" height="14" />

<textFieldExpression class="java.lang.Integer">

<![CDATA[$F{order_count}]]>

</textFieldExpression>

</textField>

<textField>

<reportElement x="309" y="0" width="100" height="14" />

<textFieldExpression class="java.lang.Double">

<![CDATA[$F{quantity}]]>

</textFieldExpression>

</textField>

<textField>

<reportElement x="409" y="0" width="89" height="14" />

<textFieldExpression class="java.lang.Double">

<![CDATA[$F{value}]]>

</textFieldExpression>

</textField>

<textField>

<reportElement x="529" y="0" width="89" height="14" />

<textFieldExpression class="java.lang.Double">

<![CDATA[$F{perf_bps}]]>

</textFieldExpression>

</textField>

<textField>

<reportElement x="638" y="0" width="110" height="14" />

<textFieldExpression class="java.lang.Double">

<![CDATA[$F{perf_bps_stddev}]]>

</textFieldExpression>

</textField>

<textField>

<reportElement x="748" y="0" width="80" height="14" />

<textFieldExpression class="java.lang.Double">

<![CDATA[$F{duration}]]>

</textFieldExpression>

</textField>

 

 

</band>

</detail>

 

<summary>

<band height="756">

<staticText>

<reportElement x="0" y="0" width="100" height="14" />

<textElement>

<font isBold="true"/>

</textElement>

<text>GSAT_VWAP</text>

</staticText>

<timeSeriesChart>

<chart evaluationTime="Report">

<reportElement mode="Opaque" x="0" y="14" width="750" height="175" />

</chart>

<timeSeriesDataset>

<dataset>

<datasetRun subDataset="history_perf">

<datasetParameter name="startdate">

<datasetParameterExpression>

<![CDATA[$F{order_date}]]>

</datasetParameterExpression>

</datasetParameter>

 

<datasetParameter name="enddate">

<datasetParameterExpression>

<![CDATA[$F{order_date}]]>

</datasetParameterExpression>

</datasetParameter>

</datasetRun>

 

</dataset>

 

 

<timeSeries>

<seriesExpression>$F{exchange}</seriesExpression>

<timePeriodExpression>$F{order_date}</timePeriodExpression>

<valueExpression>$F{perf_bps}</valueExpression>

<labelExpression></labelExpression>

</timeSeries>

</timeSeriesDataset>

<timeSeriesPlot> <plot/></timeSeriesPlot>

</timeSeriesChart>

 

<staticText>

<reportElement x="0" y="189" width="100" height="14" />

<textElement>

<font isBold="true"/>

</textElement>

<text>GSAT_Participate</text>

</staticText>

<timeSeriesChart>

<chart evaluationTime="Report">

<reportElement mode="Opaque" x="0" y="203" width="750" height="175" />

</chart>

<timeSeriesDataset>

<dataset>

<datasetRun subDataset="history_perf2"></datasetRun>

</dataset>

<timeSeries>

<seriesExpression>$F{exchange}</seriesExpression>

<timePeriodExpression>$F{order_date}</timePeriodExpression>

<valueExpression>$F{perf_bps}</valueExpression>

<labelExpression></labelExpression>

</timeSeries>

</timeSeriesDataset>

<timeSeriesPlot> <plot/></timeSeriesPlot>

</timeSeriesChart>

 

 

<staticText>

<reportElement x="0" y="378" width="100" height="14" />

<textElement>

<font isBold="true"/>

</textElement>

<text>HullVWAP</text>

</staticText>

<timeSeriesChart>

<chart evaluationTime="Report">

<reportElement mode="Opaque" x="0" y="392" width="750" height="175" />

</chart>

<timeSeriesDataset>

<dataset>

<datasetRun subDataset="history_perf3"></datasetRun>

</dataset>

<timeSeries>

<seriesExpression>$F{exchange}</seriesExpression>

<timePeriodExpression>$F{order_date}</timePeriodExpression>

<valueExpression>$F{perf_bps}</valueExpression>

<labelExpression></labelExpression>

</timeSeries>

</timeSeriesDataset>

<timeSeriesPlot> <plot/></timeSeriesPlot>

</timeSeriesChart>

 

<staticText>

<reportElement x="0" y="567" width="100" height="14" />

<textElement>

<font isBold="true"/>

</textElement>

<text>Participate</text>

</staticText>

<timeSeriesChart>

<chart evaluationTime="Report">

<reportElement mode="Opaque" x="0" y="581" width="750" height="175" />

</chart>

<timeSeriesDataset>

<dataset>

<datasetRun subDataset="history_perf4"></datasetRun>

</dataset>

<timeSeries>

<seriesExpression>$F{exchange}</seriesExpression>

<timePeriodExpression>$F{order_date}</timePeriodExpression>

<valueExpression>$F{perf_bps}</valueExpression>

<labelExpression></labelExpression>

</timeSeries>

</timeSeriesDataset>

<timeSeriesPlot> <plot/></timeSeriesPlot>

</timeSeriesChart>

 

</band>

</summary>

</jasperReport>

Link to comment
Share on other sites

I did another test.

 

<subDataset name="history_perf">

<parameter name="startdate" class="java.util.Date"/>

<parameter name="enddate" class="java.util.Date"/>

<queryString>

<![CDATA[select perf_bps, order_date,exchange from daily_perf

where algorithm_name='GSAT_VWAP'

and order_date>=$P{startdate}

group by order_date

]]>

</queryString>

 

======

I replace order_date<=$P{enddate} with order_date>=$P{startdate.

 

The result is the same, the value of enddate wasn't passed to the query. but the value of ${orderdate} was pass to the query.

 

Really weird.

Link to comment
Share on other sites

Oh, who can help me!

 

I just cann't figure out why the value cann't be passed to $P{startdate},$P{enddate}

 

But the value can be passed to $P{orderdate}

 

Is there anything with the java code?

 

================

HashMap parameterMap=new HashMap();

parameterMap.put("orderdate", string2Time(orderDate));

parameterMap.put("startdate", string2Time(startDate));

parameterMap.put("enddate", string2Time(endDate));

System.out.println("Report Date:" + string2Time(orderDate));

System.out.println("Start Date:" + string2Time(startDate));

System.out.println("End Date:" + string2Time(endDate));

System.out.println("Filling report...");

System.setProperty("java.awt.headless","true");

JasperFillManager.fillReportToFile(REPORT_DIRECTORY + "/" + reportName + ".jasper",

parameterMap, conn);

 

 

Thanks!!!!

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