[#4654] - setTimePeriod Missing

Jaspersoft Community 'Read-Only' as of July 8, 2022

Transition to New TIBCO Community Just Weeks Away

You can still search, review wiki content, and review discussions in read-only mode. Please email community@tibco.com with questions or issues requiring TIBCO review or response.

Category:
Bug report
Priority:
Normal
Status:
Acknowledged
Project: Severity:
Major
Resolution:
Open
Component: Reproducibility:
Always
Assigned to:

Hi,

public class JRFillTimeSeriesDataset // ...
{
public void setTimePeriod(Class timePeriod) {
}
}

Need this method implemented.

thangalin's picture
1461
Joined: Apr 21 2008 - 4:34am
Last seen: 2 years 7 months ago

10 Comments:

#1

public void setTimePeriod(Class timePeriod) {
((JRTimeSeriesDataset)parent).setTimePeriod( timePeriod );
}

#2

3.7.1.

#3

You'll need to detail a case on why you need the method implemented. (I know that having an empty method doesn't make sense, it should throw an exception if the method is not meant to be called).

The implementation that you propose will not be accepted because it modifies the JasperReport object used by the fill process.

Regards,
Lucian

#4

Without this method there is no way to create a trend report whereby the user can specify what unit of time period to use (e.g., from a web page form). Instead, you would have to create one report for every time period.

For example:

http://stackoverflow.com/questions/2504229/best-fit-curve-for-trend-line

If this method remains unimplemented in the next version, we will have to remember to re-implement it ourselves, or the reports shown on that StackOverflow question will break.

#5

Depending on the value the user selects, the following code dynamically changes a dataset's timeperiod accordingly:

protected void configureTrendLine()
throws JRRuntimeException {
String timeframe = getParameterValue( "TimeFrame" ).toString();
int datapoints = HOURS_PER_DAY;

if( "incident_hour".equalsIgnoreCase( timeframe ) ) {
datapoints = setTimeFrameHour();
}
else if( "incident_day".equalsIgnoreCase( timeframe ) ) {
datapoints = setTimeFrameDay();
}
else if( "incident_week".equalsIgnoreCase( timeframe ) ) {
datapoints = setTimeFrameWeek();
}
else if( "incident_month".equalsIgnoreCase( timeframe ) ) {
datapoints = setTimeFrameMonth();
}
else if( "incident_year".equalsIgnoreCase( timeframe ) ) {
datapoints = setTimeFrameYear();
}

// Remove the trend line when too few data points are present.
//
setRemoveTrendLine( datapoints < MIN_DATAPOINTS_FOR_TREND );
}

private void setTimeFrame( Class c ) {
getDataset().setTimePeriod( c );
}

protected JRTimeSeriesDataset getDataset() {
return (JRTimeSeriesDataset)getChart().getDataset();
}

protected int setTimeFrameWeek() {
return setTimeFrame( org.jfree.data.time.Week.class );
}

There is no way to implement this feature if the setTimePeriod method is empty. I do not understand why changing the JasperReport object is a bad thing.

The given method implementation works as expected.

#6

If there is another way to dynamically change the TimePeriod for a Dataset so that the user can dictate the time frame, I'd really appreciate knowing. I could see no other way.

#7

The JasperReport object should not be changed by the fill because some people might use a single object to fill several reports simultaneously (e.g. with different parameter values).

A better solution is to keep the time period type as a field in JRFillTimeSeriesDataset, and change that in setTimePeriod().

There's something I'm not clear about though. Where are you calling this code? Is it in a chart customizer? It looks to me that the chart customizer is too late for changing the time period..

#8

Here's the problem, Lucian:

http://i.imgur.com/VIvrA.png

That's not an expression. That means once you create the chart's "Time period", it cannot be (easily) changed.

If you wanted to reuse the same report, but give the users the ability to change the time series, you have two options:

1. (a) Duplicate the chart for each Time period.
1. (b) Set a PrintWhenExpression values using the parameter that controls the Time period.

For example, if the user selects "Hourly" then the Year, Quarter, Month, Week, Day, Minute, and Second charts would not be printed. But that means having 8 copies of the same chart.

Problem: When you have to fix a mistake, or need to change the chart, you have to remember to update 8 charts that are all the same.

-or-

2. Add some code that assigns the appropriate org.jfree.data.time.X class to the JRTimeSeriesDataset's time period.

Problem: The method for setTimePeriod() is unimplemented.

The code is being called within a chart customizer:

public abstract class SplineCustomizer
extends JRAbstractChartCustomizer {

public void customize( JFreeChart jFreeChart, JRChart jrChart ) {
configureTrendLine();
}
}

( See also: http://jasperforge.org/plugins/mantis/view.php?id=4657 )

For me, the best solution would be to have two options. The basic option is just to select the Time period as shown in the screen shot.

The Advanced Options would allow you to make it an expression that maps a string version of the Time period to the class. For example "Year" means to use org.jfree.data.time.Year.class.

That way report developers are free to make the time period completely configurable, without having to have octuplicated code. This could also open the door for a factory implementation that allows bi-weekly, bi-monthly, or any other type of time period that is not natively supported by the framework.

#9

Also, implementing the method as I first suggested worked. It wasn't too late to change the Time period from the chart customizer.

#10

I Have a problem, in set timePeriod in my JRAbstractChartCustomizer sub class, in implementation of the method:
customize(JFreeChart pJFreeChart, JRChart pJRChart),
i have access to all Reports parameters, but if set the timePeriod the chart no plot changes.
obs: i implements the method:

public void setTimePeriod(Class timePeriod) {
((JRTimeSeriesDataset)parent).setTimePeriod( timePeriod );
}

if override the init method:
init(JRBaseFiller pJRBaseFiller, JRFillChart pJRFillChart)
the chart is changed by setter setTimePeriod(Class timePeriod),
but i have no access to Reports parameters ( all null ),
esencials to change period.

The reports parameters must be loaded before method JRAbstractChartCustomizer.ini called.

Has Solution ?

Tanks.
Sorry my bad english.

Feedback
randomness