예제 #1
0
 public static XYDifferenceRenderer getXYDifferenceRenderer() {
   XYDifferenceRenderer r = new XYDifferenceRenderer(Color.green, new Color(229, 255, 247), false);
   r.setSeriesPaint(0, Color.RED);
   r.setSeriesPaint(1, Color.blue);
   r.setBaseShape(new Rectangle(1, 1));
   r.setShapesVisible(true);
   r.setBaseToolTipGenerator(ChartToolTipGenerators.DatedToolTipGenerator());
   return r;
 }
 /**
  * Returns a clone of the renderer.
  *
  * @return A clone.
  * @throws CloneNotSupportedException if the renderer cannot be cloned.
  */
 public Object clone() throws CloneNotSupportedException {
   XYDifferenceRenderer clone = (XYDifferenceRenderer) super.clone();
   clone.legendLine = ShapeUtilities.clone(this.legendLine);
   return clone;
 }
  /**
   * @param forecast
   * @param settings (next days)
   * @return
   */
  public JFreeChart createXYPlot(
      final LiquidityForecast forecast, final LiquidityForecastSettings settings) {
    Validate.isTrue(settings.getNextDays() > 0 && settings.getNextDays() < 500);

    final LiquidityForecastCashFlow cashFlow =
        new LiquidityForecastCashFlow(forecast, settings.getNextDays());

    final TimeSeries accumulatedSeries =
        new TimeSeries(I18n.getString("plugins.liquidityplanning.forecast.dueDate"));
    final TimeSeries accumulatedSeriesExpected =
        new TimeSeries(
            PFUserContext.getLocalizedString("plugins.liquidityplanning.forecast.expected"));
    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();
  }