One solution requires the following elements:
BezierLineCustomizer to make lines curved.RunningAverageIncrementer to calculate the average value based on a variable.- iReport variable using
RunningAverageIncremeter .
BezierLineCustomizer Class
public class BezierLineCustomizer implements JRChartCustomizer { public BezierLineCustomizer() { } public void customize( JFreeChart jFreeChart, JRChart jrChart ) { XYPlot xyPlot = ( XYPlot )jFreeChart.getPlot(); XYSplineRenderer splineRenderer = new XYSplineRenderer();
Class RunningAverageIncrementer
public class RunningAverageIncrementer implements JRIncrementer { private static final int DEFAULT_TALLIES = 128; private static final int DEFAULT_SLIDING_WINDOW_SIZE = 30; private List<Double> values = new ArrayList<Double>( DEFAULT_TALLIES ); public RunningAverageIncrementer() { } private double calculateAverage() { double result = 0.0; List<Double> values = getValues(); for( Double d: getValues() ) { result += d.doubleValue(); } return result / values.size(); } private void recordValue( Double value ) { List<Double> values = getValues();
iReport Variable
Create a variable that uses the RunningAverageIncrementerFactory class (exercise to the left of the reader). Set the variable expression to the constructed value. Set its initial value to zero.
Spline
Set the TimeSeries chart class property property to use the BezierLineCustomizer class.
Result
After these changes, the average mileage is clearly visible:

source share