Java 类org.jfree.chart.renderer.xy.XYDifferenceRenderer 实例源码

项目:dynamicreports-jasper    文件:DifferenceRendererCustomizer.java   
@Override
public void customize(JFreeChart chart, ReportParameters reportParameters) {
    XYLineAndShapeRenderer lineRenderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer();
   XYDifferenceRenderer renderer = new XYDifferenceRenderer();

   renderer.setBaseItemLabelsVisible(lineRenderer.getBaseItemLabelsVisible());
   renderer.setBaseItemLabelFont(lineRenderer.getBaseItemLabelFont());
   renderer.setBaseItemLabelPaint(lineRenderer.getBaseItemLabelPaint());
   renderer.setBaseItemLabelGenerator(lineRenderer.getBaseItemLabelGenerator());

   if (positiveColor != null) {
    renderer.setPositivePaint(positiveColor);
   }
   if (negativeColor != null) {
    renderer.setNegativePaint(negativeColor);
   }
   if (showShapes != null) {
    renderer.setShapesVisible(showShapes);
   }
   chart.getXYPlot().setRenderer(renderer);
}
项目:parabuild-ci    文件:XYDifferenceRendererTests.java   
/**
 * Two objects that are equal are required to return the same hashCode. 
 */
public void testHashcode() {
    XYDifferenceRenderer r1 = new XYDifferenceRenderer(Color.red, Color.blue, false);
    XYDifferenceRenderer r2 = new XYDifferenceRenderer(Color.red, Color.blue, false);
    assertTrue(r1.equals(r2));
    int h1 = r1.hashCode();
    int h2 = r2.hashCode();
    assertEquals(h1, h2);
}
项目:parabuild-ci    文件:XYDifferenceRendererTests.java   
/**
 * Two objects that are equal are required to return the same hashCode. 
 */
public void testHashcode() {
    XYDifferenceRenderer r1 
        = new XYDifferenceRenderer(Color.red, Color.blue, false);
    XYDifferenceRenderer r2 
        = new XYDifferenceRenderer(Color.red, Color.blue, false);
    assertTrue(r1.equals(r2));
    int h1 = r1.hashCode();
    int h2 = r2.hashCode();
    assertEquals(h1, h2);
}
项目:JGrafix    文件:IndiceBollinger.java   
@Override
public void plotar(final XYPlot plot, final JanelaGraficos janela, final int contador) {
    float[] color = getCor().getComponents(null);
    XYDifferenceRenderer r = new XYDifferenceRenderer(new Color(color[0],color[1],color[2],.1f), Color.red, false);
    r.setStroke(new BasicStroke(.75f));
    r.setPaint(getCor());
    plot.setRenderer(contador, r);
    plot.setDataset(contador, getDataSet(janela));
}
项目:dotalys-cli    文件:ChartCreator.java   
public static JFreeChart createTeamGoldDifferenceGraph( AppState appState ) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart( GameStatisticsComponent.TEAM_XP, Statics.EXPERIENCE, "Time",
                    createTeamGoldDiffDataSet( appState ), true, // legend
                    true, // tool tips
                    false // URLs
                    );

    final XYDifferenceRenderer renderer = new XYDifferenceRenderer( Color.GREEN, Color.RED, false );

    renderer.setSeriesPaint( 0, Color.GREEN );
    renderer.setSeriesPaint( 1, Color.RED );
    final XYPlot plot = chart.getXYPlot();
    plot.setRenderer( renderer );

    final DateAxis domainAxis = new DateAxis( Statics.TIME );
    domainAxis.setTickMarkPosition( DateTickMarkPosition.MIDDLE );
    domainAxis.setLowerMargin( 0.0 );
    domainAxis.setUpperMargin( 0.0 );
    plot.setDomainAxis( domainAxis );
    plot.setForegroundAlpha( 0.5f );

    final NumberAxis rangeAxis = new NumberAxis( Statics.GOLD );
    rangeAxis.setLowerMargin( 0.15 );
    rangeAxis.setUpperMargin( 0.15 );
    plot.setRangeAxis( rangeAxis );
    return chart;
}
项目:dotalys-cli    文件:ChartCreator.java   
public static JFreeChart createTeamXpDifferenceGraph( AppState state ) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart( GameStatisticsComponent.TEAM_XP, Statics.EXPERIENCE, "Time",
                    createTeamXPDiffDataSet( state ), true, // legend
                    true, // tool tips
                    false // URLs
                    );

    final XYDifferenceRenderer renderer = new XYDifferenceRenderer( Color.GREEN, Color.RED, false );

    renderer.setSeriesPaint( 0, Color.GREEN );
    renderer.setSeriesPaint( 1, Color.RED );
    final XYPlot plot = chart.getXYPlot();
    plot.setRenderer( renderer );

    final DateAxis domainAxis = new DateAxis( Statics.TIME );
    domainAxis.setTickMarkPosition( DateTickMarkPosition.MIDDLE );
    domainAxis.setLowerMargin( 0.0 );
    domainAxis.setUpperMargin( 0.0 );
    plot.setDomainAxis( domainAxis );
    plot.setForegroundAlpha( 0.5f );

    final NumberAxis rangeAxis = new NumberAxis( Statics.EXPERIENCE );
    rangeAxis.setLowerMargin( 0.15 );
    rangeAxis.setUpperMargin( 0.15 );
    plot.setRangeAxis( rangeAxis );
    return chart;

}
项目:HTML5_WebSite    文件:DifferenceChartDemo1.java   
/**
   * Creates a chart.
   * 
   * @param dataset  the dataset.
   * 
   * @return The chart.
   */
  protected JFreeChart createChart(XYDataset dataset) {
      JFreeChart chart = ChartFactory.createTimeSeriesChart(
          chartTitle,
          domainLabel, rangeLabel,
          dataset,
          !legendPanelOn,  // legend
          true,  // tool tips
          false  // URLs
      );
      chart.setBackgroundPaint(Color.white);

      XYPlot plot = chart.getXYPlot();
      plot.setRenderer(new XYDifferenceRenderer(
          Color.green, Color.red, false)
      );
      plot.setBackgroundPaint(Color.lightGray);
      plot.setDomainGridlinePaint(Color.white);
      plot.setRangeGridlinePaint(Color.white);
      plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

XYItemRenderer renderer = plot.getRenderer();
renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

      ValueAxis domainAxis = new DateAxis("Time");
      domainAxis.setLowerMargin(0.0);
      domainAxis.setUpperMargin(0.0);
      plot.setDomainAxis(domainAxis);
      plot.setForegroundAlpha(0.5f);  

//setXSummary(dataset) X is time;          
      return chart; 

  }
项目:HTML5_WebSite    文件:ChartGenerator_JTable.java   
private JFreeChart createXYDifferenceChart(String title, String xLabel, String yLabel, XYDataset dataset) {
 JFreeChart chart = ChartFactory.createTimeSeriesChart(
           title,
           xLabel, yLabel,
           dataset,
           true,  // legend
           true,  // tool tips
           false  // URLs
       );
       chart.setBackgroundPaint(Color.white);

       XYPlot plot = chart.getXYPlot();
       plot.setRenderer(new XYDifferenceRenderer(
           Color.green, Color.red, false)
       );
       plot.setBackgroundPaint(Color.lightGray);
       plot.setDomainGridlinePaint(Color.white);
       plot.setRangeGridlinePaint(Color.white);
       plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

    XYItemRenderer renderer = plot.getRenderer();
    //renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());
    setDateAxis(plot);

    /*   ValueAxis domainAxis = new DateAxis("Time");
       domainAxis.setLowerMargin(0.0);
       domainAxis.setUpperMargin(0.0);
       plot.setDomainAxis(domainAxis);
       plot.setForegroundAlpha(0.5f);  */

    //setXSummary(dataset) X is time;
       return chart;
}
项目:nabs    文件:XYDifferenceRendererTests.java   
/**
 * Two objects that are equal are required to return the same hashCode. 
 */
public void testHashcode() {
    XYDifferenceRenderer r1 
        = new XYDifferenceRenderer(Color.red, Color.blue, false);
    XYDifferenceRenderer r2 
        = new XYDifferenceRenderer(Color.red, Color.blue, false);
    assertTrue(r1.equals(r2));
    int h1 = r1.hashCode();
    int h2 = r2.hashCode();
    assertEquals(h1, h2);
}
项目:astor    文件:XYDifferenceRendererTests.java   
/**
 * Two objects that are equal are required to return the same hashCode.
 */
public void testHashcode() {
    XYDifferenceRenderer r1
        = new XYDifferenceRenderer(Color.red, Color.blue, false);
    XYDifferenceRenderer r2
        = new XYDifferenceRenderer(Color.red, Color.blue, false);
    assertTrue(r1.equals(r2));
    int h1 = r1.hashCode();
    int h2 = r2.hashCode();
    assertEquals(h1, h2);
}
项目:astor    文件:XYDifferenceRendererTests.java   
/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
public void testGetLegendItemSeriesIndex() {
    XYSeriesCollection d1 = new XYSeriesCollection();
    XYSeries s1 = new XYSeries("S1");
    s1.add(1.0, 1.1);
    XYSeries s2 = new XYSeries("S2");
    s2.add(1.0, 1.1);
    d1.addSeries(s1);
    d1.addSeries(s2);

    XYSeriesCollection d2 = new XYSeriesCollection();
    XYSeries s3 = new XYSeries("S3");
    s3.add(1.0, 1.1);
    XYSeries s4 = new XYSeries("S4");
    s4.add(1.0, 1.1);
    XYSeries s5 = new XYSeries("S5");
    s5.add(1.0, 1.1);
    d2.addSeries(s3);
    d2.addSeries(s4);
    d2.addSeries(s5);

    XYDifferenceRenderer r = new XYDifferenceRenderer();
    XYPlot plot = new XYPlot(d1, new NumberAxis("x"),
            new NumberAxis("y"), r);
    plot.setDataset(1, d2);
    /*JFreeChart chart =*/ new JFreeChart(plot);
    LegendItem li = r.getLegendItem(1, 2);
    assertEquals("S5", li.getLabel());
    assertEquals(1, li.getDatasetIndex());
    assertEquals(2, li.getSeriesIndex());
}
项目:dynamicreports-jasper    文件:DifferenceChartTest.java   
@Override
public void test() {
    super.test();

    numberOfPagesTest(1);

    JFreeChart chart = getChart("summary.chart1", 0);
    XYItemRenderer renderer = chart.getXYPlot().getRenderer();
    Assert.assertEquals("renderer", XYDifferenceRenderer.class, renderer.getClass());
    Assert.assertFalse("show shapes", ((XYDifferenceRenderer) renderer).getShapesVisible());
    Assert.assertEquals("positive paint", Color.BLUE, ((XYDifferenceRenderer) renderer).getPositivePaint());
    Assert.assertEquals("negative paint", Color.MAGENTA, ((XYDifferenceRenderer) renderer).getNegativePaint());

    chart = getChart("summary.chart2", 0);
    Axis axis = chart.getXYPlot().getDomainAxis();
    Assert.assertEquals("category label", "time", axis.getLabel());
    Assert.assertEquals("category label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("category label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());
    Assert.assertTrue("vertical tick labels", ((ValueAxis) axis).isVerticalTickLabels());

    chart = getChart("summary.chart3", 0);
    axis = chart.getXYPlot().getRangeAxis();
    Assert.assertEquals("value label", "value", axis.getLabel());
    Assert.assertEquals("value label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("value label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    Assert.assertEquals("tick label mask", "10.00", ((NumberAxis) axis).getNumberFormatOverride().format(10));
    //Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());
    Assert.assertEquals("range min value", 1d, ((ValueAxis) axis).getLowerBound());
    Assert.assertEquals("range max value", 15d, ((ValueAxis) axis).getUpperBound());
    Assert.assertTrue("vertical tick labels", ((ValueAxis) axis).isVerticalTickLabels());
}
项目:parabuild-ci    文件:XYDifferenceRendererTests.java   
/**
 * Problem that the equals(...) method distinguishes all fields.
 */
public void testEquals() {
    XYDifferenceRenderer r1 = new XYDifferenceRenderer(Color.red, Color.blue, false);
    XYDifferenceRenderer r2 = new XYDifferenceRenderer(Color.red, Color.blue, false);
    assertEquals(r1, r2);
}
项目:Pac-Man    文件:CenterPanel.java   
public XYPlot createSubplot(int numOfPlot) {
    ArrayList<XYSeries> serie = new ArrayList<>(4);
    serie.add(new XYSeries("Worst of generation"));
    serie.add(new XYSeries("Best of generation"));
    serie.add(new XYSeries("Generation average"));
    serie.add(new XYSeries("Absolute best"));
    this.series.add(serie);

    XYSeriesCollection dataset1 = new XYSeriesCollection();
    XYSeriesCollection dataset2 = new XYSeriesCollection();
    ArrayList<XYSeriesCollection> datasetCol = new ArrayList<>(2);
    datasetCol.add(dataset1);
    datasetCol.add(dataset2);
    this.datasets.add(datasetCol);

    XYPlot plot = new XYPlot();
    plot.setDataset(0, dataset2);
    XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer(true, false);
    lineRenderer.setSeriesPaint(0, blue1);
    lineRenderer.setSeriesStroke(0, stroke1);
    lineRenderer.setSeriesPaint(1, blue2);
    lineRenderer.setSeriesStroke(1, stroke2);
    if(numOfPlot == 0) {
        lineRenderer.setSeriesVisibleInLegend(0, true);
        lineRenderer.setSeriesVisibleInLegend(1, true);
    }
    else {
        lineRenderer.setSeriesVisibleInLegend(0, false);
        lineRenderer.setSeriesVisibleInLegend(1, false);
    }
    plot.setRenderer(0, lineRenderer);

    plot.setDataset(1, dataset1);
    XYDifferenceRenderer diffRenderer = new XYDifferenceRenderer(
            blue, blue, false
        );
    diffRenderer.setSeriesPaint(0, transparent);
    diffRenderer.setSeriesPaint(1, transparent);
    diffRenderer.setSeriesVisibleInLegend(0, false);
    diffRenderer.setSeriesVisibleInLegend(1, false);
    plot.setRenderer(1, diffRenderer);
    plot.setOutlinePaint(null);
    plot.setBackgroundPaint(Color.white);
    plot.setForegroundAlpha(1);
    plot.setDomainGridlinePaint(lighterGray);
    plot.setRangeGridlinePaint(lighterGray);

    NumberAxis domainAxis = new NumberAxis("");
    plot.setDomainAxis(domainAxis);
    domainAxis.setTickMarkPaint(Color.black);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setAutoRangeIncludesZero(false);

    NumberAxis rangeAxis = new NumberAxis(this.gCtrl.getFitnessName(numOfPlot));
    plot.setRangeAxis(rangeAxis);
    rangeAxis.setTickMarkPaint(Color.black);
    rangeAxis.setLowerMargin(0.01);
    rangeAxis.setUpperMargin(0.01);
    rangeAxis.setAutoRangeIncludesZero(false);

    return plot;
}
项目:astor    文件:SWTTimeSeriesDemo.java   
/**
 * Creates a chart.
 *
 * @param dataset  a dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "Legal & General Unit Trust Prices",  // title
        "Date",             // x-axis label
        "Price Per Unit",   // y-axis label
        dataset,            // data
        true,               // create legend?
        true,               // generate tooltips?
        false               // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    //plot.setForegroundAlpha(0.5f);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
    }

    // code to test the alpha channel
    IntervalMarker interv = new IntervalMarker(120, 150,
            Color.blue, new BasicStroke(5.0f),null,null,0.2f);
    plot.addRangeMarker(interv);

    // code to test the alpha channel within awt colors
    XYDifferenceRenderer differenceRenderer= new XYDifferenceRenderer(
            new Color(255, 0, 0, 128),new Color(0, 255, 0, 128), false);
    plot.setRenderer(differenceRenderer);

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

    return chart;

}
项目:astor    文件:XYDifferenceRendererTests.java   
/**
 * Verify that this class implements {@link PublicCloneable}.
 */
public void testPublicCloneable() {
    XYDifferenceRenderer r1 = new XYDifferenceRenderer();
    assertTrue(r1 instanceof PublicCloneable);
}
项目:projectforge-webapp    文件:TimesheetDisciplineChartBuilder.java   
/**
 * Ein Diagramm, welches über die letzten n Tage die kummulierten IST-Arbeitsstunden und als Soll-Wert die tatsächlich gebuchten
 * Zeitberichte aufträgt. Dies wird in einem Differenz-XY-Diagramm visualisiert. Die Darstellung soll motivieren, dass Projektmitarbeiter
 * ihre Zeitberichte möglichst zeitnah eintragen.
 * @param timesheetDao
 * @param userId
 * @param workingHoursPerDay
 * @param forLastNDays
 * @param shape e. g. new Ellipse2D.Float(-3, -3, 6, 6) or null, if no marker should be printed.
 * @param stroke e. g. new BasicStroke(3.0f).
 * @param showAxisValues
 * @return
 */
public JFreeChart create(final TimesheetDao timesheetDao, final Integer userId, final double workingHoursPerDay,
    final short forLastNDays, final boolean showAxisValues)
{
  final DayHolder dh = new DayHolder();
  final TimesheetFilter filter = new TimesheetFilter();
  filter.setStopTime(dh.getDate());
  dh.add(Calendar.DATE, -forLastNDays);
  filter.setStartTime(dh.getDate());
  filter.setUserId(userId);
  filter.setOrderType(OrderDirection.ASC);
  final List<TimesheetDO> list = timesheetDao.getList(filter);
  final TimeSeries sollSeries = new TimeSeries("Soll");
  final TimeSeries istSeries = new TimeSeries("Ist");
  planWorkingHours = 0;
  actualWorkingHours = 0;
  final Iterator<TimesheetDO> it = list.iterator();
  TimesheetDO current = null;
  if (it.hasNext() == true) {
    current = it.next();
  }
  for (int i = 0; i <= forLastNDays; i++) {
    while (current != null && (dh.isSameDay(current.getStartTime()) == true || current.getStartTime().before(dh.getDate()) == true)) {
      actualWorkingHours += ((double) current.getWorkFractionDuration()) / 3600000;
      if (it.hasNext() == true) {
        current = it.next();
      } else {
        current = null;
        break;
      }
    }
    if (dh.isWorkingDay() == true) {
      final BigDecimal workFraction = dh.getWorkFraction();
      if (workFraction != null) {
        planWorkingHours += workFraction.doubleValue() * workingHoursPerDay;
      } else {
        planWorkingHours += workingHoursPerDay;
      }
    }
    final Day day = new Day(dh.getDayOfMonth(), dh.getMonth() + 1, dh.getYear());
    sollSeries.add(day, planWorkingHours);
    istSeries.add(day, actualWorkingHours);
    dh.add(Calendar.DATE, 1);
  }
  final TimeSeriesCollection dataset = new TimeSeriesCollection();
  dataset.addSeries(sollSeries);
  dataset.addSeries(istSeries);
  final XYChartBuilder cb = new XYChartBuilder(null,  null,  null,  dataset, false);
  final XYDifferenceRenderer diffRenderer = new XYDifferenceRenderer(cb.getRedFill(), cb.getGreenFill(), true);
  diffRenderer.setSeriesPaint(0, cb.getRedMarker());
  diffRenderer.setSeriesPaint(1, cb.getGreenMarker());
  cb.setRenderer(0, diffRenderer).setStrongStyle(diffRenderer, false, sollSeries, istSeries);
  cb.setDateXAxis(true).setYAxis(true, "hours");
  return cb.getChart();
}
项目:projectforge-webapp    文件:TimesheetDisciplineChartBuilder.java   
/**
 * Ein Diagramm, welches über die letzten n Tage die Tage visualisiert, die zwischen Zeitberichtsdatum und Zeitpunkt der tatsächlichen
 * Buchung liegen.
 * @param timesheetDao
 * @param userId
 * @param forLastNDays
 * @param shape e. g. new Ellipse2D.Float(-3, -3, 6, 6) or null, if no marker should be printed.
 * @param stroke e. g. new BasicStroke(3.0f).
 * @param showAxisValues
 * @return
 */
public JFreeChart create(final TimesheetDao timesheetDao, final Integer userId, final short forLastNDays, final boolean showAxisValues)
{
  final DayHolder dh = new DayHolder();
  final TimesheetFilter filter = new TimesheetFilter();
  filter.setStopTime(dh.getDate());
  dh.add(Calendar.DATE, -forLastNDays);
  filter.setStartTime(dh.getDate());
  filter.setUserId(userId);
  filter.setOrderType(OrderDirection.ASC);
  final List<TimesheetDO> list = timesheetDao.getList(filter);
  final TimeSeries planSeries = new TimeSeries("Soll");
  final TimeSeries actualSeries = new TimeSeries("Ist");
  final Iterator<TimesheetDO> it = list.iterator();
  TimesheetDO current = null;
  if (it.hasNext() == true) {
    current = it.next();
  }
  long numberOfBookedDays = 0;
  long totalDifference = 0;
  for (int i = 0; i <= forLastNDays; i++) {
    long difference = 0;
    long totalDuration = 0; // Weight for average.
    while (current != null && (dh.isSameDay(current.getStartTime()) == true || current.getStartTime().before(dh.getDate()) == true)) {
      final long duration = current.getWorkFractionDuration();
      difference += (current.getCreated().getTime() - current.getStartTime().getTime()) * duration;
      totalDuration += duration;
      if (it.hasNext() == true) {
        current = it.next();
      } else {
        current = null;
        break;
      }
    }
    final double averageDifference = difference > 0 ? ((double) difference) / totalDuration / 86400000 : 0; // In days.
    final Day day = new Day(dh.getDayOfMonth(), dh.getMonth() + 1, dh.getYear());
    if (averageDifference > 0) {
      planSeries.add(day, PLANNED_AVERAGE_DIFFERENCE_BETWEEN_TIMESHEET_AND_BOOKING); // plan average
      // (PLANNED_AVERAGE_DIFFERENCE_BETWEEN_TIMESHEET_AND_BOOKING
      // days).
      actualSeries.add(day, averageDifference);
      totalDifference += averageDifference;
      numberOfBookedDays++;
    }
    dh.add(Calendar.DATE, 1);
  }
  averageDifferenceBetweenTimesheetAndBooking = numberOfBookedDays > 0 ? new BigDecimal(totalDifference).divide(new BigDecimal(
      numberOfBookedDays), 1, RoundingMode.HALF_UP) : BigDecimal.ZERO;

  final TimeSeriesCollection dataset = new TimeSeriesCollection();
  dataset.addSeries(actualSeries);
  dataset.addSeries(planSeries);
  final XYChartBuilder cb = new XYChartBuilder(null,  null,  null,  dataset, false);
  final XYDifferenceRenderer diffRenderer = new XYDifferenceRenderer(cb.getRedFill(), cb.getGreenFill(), true);
  diffRenderer.setSeriesPaint(0, cb.getRedMarker());
  diffRenderer.setSeriesPaint(1, cb.getGreenMarker());
  cb.setRenderer(0, diffRenderer).setStrongStyle(diffRenderer, false, actualSeries, planSeries);
  cb.setDateXAxis(true).setYAxis(true, "days");
  return cb.getChart();
}
项目:projectforge-webapp    文件:LiquidityChartBuilder.java   
/**
 * @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();
}
项目:dynamicreports-jasper    文件:DifferenceChartTest.java   
@Override
public void customize(JFreeChart chart, ReportParameters reportParameters) {
    XYPlot xyPlot = chart.getXYPlot();
    Assert.assertEquals("renderer", XYDifferenceRenderer.class, xyPlot.getRenderer().getClass());
 }