[#4657] - JRAbstractChartCustomizer init method ordering

Feature request
Project: Severity:
Component: Reproducibility:
Assigned to:

The JRAbstractChartCustomizer init( ... ) method cannot use the getParameterValue method (and similar metohds).

The JRAbstractChartCustomizer customize( ... ) method can use the getParameterValue method.

The parameter map should be set before the init method for JRAbstractChartCustomizer is called, thus allowing getParameterValue to return a value.

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



You'll have to explain better what the problem is.

Are you extending JRAbstractChartCustomizer and overriding init()? If so, are you calling super.init() as the first thing in your method?

The parameter map is set in the JRAbstractChartCustomizer.init() method, I don't see why you would necessarily want it to be set before.



In SplineCustomizer.java:

public abstract class SplineCustomizer
extends JRAbstractChartCustomizer {

public void init( JRBaseFiller baseFiller, JRFillChart chart ) {
super.init( baseFiller, chart );

setBaseFiller( baseFiller );
setChart( chart );

public void customize( JFreeChart jFreeChart, JRChart jrChart ) {

* Provides subclasses with an opportunity to configure the chart,
* indicate whether the trend line should be drawn, and so forth.
protected abstract void configureTrendLine() throws JRRuntimeException;

The method configureTrendLine() cannot be called within the init() method. However, the init() method is where the method should be called. The method has the following implementation:

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

This is initialization, but cannot be included in the init() method because getParameterValue( ... ) fails to return a value. It works as shown, but not within the init() method. This is because the parameter map is not initialized until after the init() method completes.


You're right, parameter values are set after JRAbstractChartCustomizer.init() is called.

We'll consider whether changing this is feasible/desirable.


Thanks. I look forward to seeing the release where this is fixed. :-)