[#4654] - setTimePeriod Missing

Bug report
Project: Severity:
Component: Reproducibility:
Assigned to:


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

Need this method implemented.

thangalin's picture
Joined: Apr 21 2008 - 4:34am
Last seen: 3 years 6 months ago



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




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.



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:


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.


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.


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.


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


Here's the problem, Lucian:


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.


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 ) {

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


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


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 ?

Sorry my bad english.