final TimeSeries worstCaseSeries = new TimeSeries(I18n.getString("plugins.liquidityplanning.forecast.worstCase"));
double accumulatedExpected = settings.getStartAmount().doubleValue();
double accumulated = accumulatedExpected;
double worstCase = accumulated;
final DayHolder dh = new DayHolder();
final Date lower = dh.getDate();
for (int i = 0; i < settings.getNextDays(); i++) {
if (log.isDebugEnabled() == true) {
log.debug("day: " + i + ", credits=" + cashFlow.getCredits()[i] + ", debits=" + cashFlow.getDebits()[i]);
}
final Day day = new Day(dh.getDayOfMonth(), dh.getMonth() + 1, dh.getYear());
if (i > 0) {
accumulated += cashFlow.getDebits()[i - 1].doubleValue() + cashFlow.getCredits()[i - 1].doubleValue();
accumulatedExpected += cashFlow.getDebitsExpected()[i - 1].doubleValue() + cashFlow.getCreditsExpected()[i - 1].doubleValue();
worstCase += cashFlow.getCredits()[i - 1].doubleValue();
}
accumulatedSeries.add(day, accumulated);
accumulatedSeriesExpected.add(day, accumulatedExpected);
worstCaseSeries.add(day, worstCase);
dh.add(Calendar.DATE, 1);
}
dh.add(Calendar.DATE, -1);
final XYChartBuilder cb = new XYChartBuilder(null, null, null, null, true);
int counter = 0;
final TimeSeriesCollection xyDataSeries = new TimeSeriesCollection();
xyDataSeries.addSeries(accumulatedSeries);
xyDataSeries.addSeries(worstCaseSeries);
final XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer(true, false);
lineRenderer.setSeriesPaint(0, Color.BLACK);
lineRenderer.setSeriesVisibleInLegend(0, true);
lineRenderer.setSeriesPaint(1, cb.getGrayMarker());
lineRenderer.setSeriesStroke(1, cb.getDashedStroke());
lineRenderer.setSeriesVisibleInLegend(1, true);
cb.setRenderer(counter, lineRenderer).setDataset(counter++, xyDataSeries);
final TimeSeriesCollection accumulatedSet = new TimeSeriesCollection();
accumulatedSet.addSeries(accumulatedSeriesExpected);
final XYDifferenceRenderer diffRenderer = new XYDifferenceRenderer(cb.getGreenFill(), cb.getRedFill(), true);
diffRenderer.setSeriesPaint(0, cb.getRedMarker());
cb.setRenderer(counter, diffRenderer).setDataset(counter++, accumulatedSet)
.setStrongStyle(diffRenderer, false, accumulatedSeriesExpected);
diffRenderer.setSeriesVisibleInLegend(0, true);
cb.setDateXAxis(true).setDateXAxisRange(lower, dh.getDate()).setYAxis(true, null);
return cb.getChart();
}