/** Trims and transforms a big burndown chart to a small one. */
  protected JFreeChart transformToSmallChart(JFreeChart burndownChart) {
    JFreeChart chart = burndownChart;
    XYPlot plot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();

    chart.setBackgroundPaint(CHART_BACKGROUND_COLOR);
    plot.setBackgroundPaint(PLOT_BACKGROUND_COLOR);

    renderer.setSeriesPaint(BURNDOWN_SERIES_NO, BURNDOWN_SERIES_COLOR);
    renderer.setSeriesPaint(CURRENT_DAY_SERIES_NO, BURNDOWN_SERIES_COLOR);
    renderer.setSeriesPaint(SCOPING_SERIES_NO, BURNDOWN_SERIES_COLOR);
    renderer.setSeriesPaint(REFERENCE_SERIES_NO, REFERENCE_SERIES_COLOR);

    renderer.setSeriesStroke(BURNDOWN_SERIES_NO, SMALL_BURNDOWN_STROKE);
    renderer.setSeriesStroke(CURRENT_DAY_SERIES_NO, SMALL_BURNDOWN_STROKE);
    renderer.setSeriesStroke(SCOPING_SERIES_NO, SMALL_BURNDOWN_STROKE);
    renderer.setSeriesStroke(REFERENCE_SERIES_NO, SMALL_BURNDOWN_STROKE);

    renderer.setSeriesShapesVisible(BURNDOWN_SERIES_NO, false);
    renderer.setSeriesShapesVisible(CURRENT_DAY_SERIES_NO, false);
    renderer.setSeriesShapesVisible(SCOPING_SERIES_NO, false);
    renderer.setSeriesShapesVisible(REFERENCE_SERIES_NO, false);

    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.getDomainAxis().setVisible(false);
    plot.getRangeAxis().setVisible(false);

    plot.getDomainAxis().setLabel(null);
    plot.getRangeAxis().setLabel(null);

    RectangleInsets ins = new RectangleInsets(-6, -8, -3, -7);
    chart.setPadding(ins);

    if (plot.getDataset() != null) {
      TimeSeriesCollection dataset = (TimeSeriesCollection) plot.getDataset();
      // HORROR!
      // Will break horribly if some series is missing because the indexes
      // cannot be trusted!!
      // The indexes are defined as constants but the indexes come
      // directly
      // from the order in which the series are added
      // If one series is missing, EXPECTED_SERIES_NO = 4 but the index
      // for expected series is 3
      // (and it's even possible that it doesn't exist!)
      if (dataset.getSeriesCount() > EXPECTED_SERIES_NO) {
        dataset.removeSeries(EXPECTED_SERIES_NO);
      }
    }

    chart.removeLegend();
    chart.setTitle("");

    return chart;
  }
Exemplo n.º 2
0
 private XYItemRenderer getLineRenderer() throws KeyedException {
   XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer();
   lineRenderer.setDrawSeriesLineAsPath(true);
   lineRenderer.setSeriesStroke(
       0, new BasicStroke(getStrokeWidth(), BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND));
   lineRenderer.setBaseShapesVisible(false);
   return lineRenderer;
 }
Exemplo n.º 3
0
 private void configureRendererForCorrelativeData(XYLineAndShapeRenderer renderer) {
   renderer.setSeriesLinesVisible(1, false);
   renderer.setSeriesShapesVisible(1, true);
   renderer.setSeriesStroke(1, new BasicStroke(1.0f));
   renderer.setSeriesPaint(1, StatisticChartStyling.CORRELATIVE_POINT_PAINT);
   renderer.setSeriesFillPaint(1, StatisticChartStyling.CORRELATIVE_POINT_FILL_PAINT);
   renderer.setSeriesShape(1, StatisticChartStyling.CORRELATIVE_POINT_SHAPE);
 }
  protected void setSeriesStyles(JFreeChart chart) {
    XYLineAndShapeRenderer rend = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer();

    rend.setSeriesPaint(BURNDOWN_SERIES_NO, BURNDOWN_SERIES_COLOR);
    rend.setSeriesShape(BURNDOWN_SERIES_NO, BURNDOWN_SERIES_SHAPE);
    rend.setSeriesShapesVisible(BURNDOWN_SERIES_NO, BURNDOWN_SERIES_SHAPE_VISIBLE);

    rend.setSeriesPaint(REFERENCE_SERIES_NO, REFERENCE_SERIES_COLOR);

    rend.setSeriesPaint(CURRENT_DAY_SERIES_NO, CURRENT_DAY_SERIES_COLOR);
    rend.setSeriesStroke(CURRENT_DAY_SERIES_NO, CURRENT_DAY_SERIES_STROKE);
    rend.setSeriesShape(CURRENT_DAY_SERIES_NO, CURRENT_DAY_SERIES_SHAPE);
    rend.setSeriesShapesVisible(CURRENT_DAY_SERIES_NO, CURRENT_DAY_SERIES_SHAPE_VISIBLE);
    rend.setSeriesShapesFilled(CURRENT_DAY_SERIES_NO, CURRENT_DAY_SERIES_SHAPE_FILLED);

    rend.setSeriesPaint(SCOPING_SERIES_NO, SCOPING_SERIES_COLOR);
    rend.setSeriesStroke(SCOPING_SERIES_NO, SCOPING_SERIES_STROKE);

    rend.setSeriesPaint(EXPECTED_SERIES_NO, EXPECTED_SERIES_COLOR);
    rend.setSeriesStroke(EXPECTED_SERIES_NO, EXPECTED_SERIES_STROKE);
  }
Exemplo n.º 5
0
 public static XYLineAndShapeRenderer getLineAndShapeRenderer(TimeSeriesCollection dataset) {
   XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
   renderer.setSeriesPaint(dataset.indexOf(dataset.getSeries("ADX")), Color.BLACK);
   renderer.setSeriesPaint(dataset.indexOf(dataset.getSeries("PlusDI")), Color.BLUE);
   renderer.setSeriesPaint(dataset.indexOf(dataset.getSeries("MinusDI")), Color.RED);
   renderer.setSeriesStroke(0, new BasicStroke(1.5f));
   renderer.setSeriesStroke(1, new BasicStroke(1.5f));
   renderer.setSeriesStroke(2, new BasicStroke(1.5f));
   //    renderer.setBaseShape(new Rectangle(1, 1));
   // renderer.setShapesVisible(true);
   renderer.setBaseToolTipGenerator(ChartToolTipGenerators.DatedToolTipGenerator());
   //    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
   //    renderer.setBaseShapesVisible(true);
   //    renderer.setDrawOutlines(true);
   //    renderer.setUseFillPaint(true);
   //    renderer.setBaseFillPaint(Color.white);
   //    renderer.setSeriesStroke(0, new BasicStroke(1.0f));
   //    renderer.setSeriesOutlineStroke(0, new BasicStroke(1.0f));
   //    renderer.setSeriesShape(0, new Ellipse2D.Double(-1.0, -1.0, 1.0, 1.0));
   //    renderer.setBaseToolTipGenerator(getToolTipGenerator());
   return renderer;
 }
  private static void configureXYLineAndShapeRenderer(
      XYLineAndShapeRenderer renderer, ValueSource valueSource, PlotInstance plotInstance) {
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    SeriesFormat seriesFormat = valueSource.getSeriesFormat();
    DimensionConfig domainConfig = valueSource.getDomainConfig();
    DimensionConfig colorDimensionConfig =
        plotInstance.getCurrentPlotConfigurationClone().getDimensionConfig(PlotDimension.COLOR);
    DimensionConfig shapeDimensionConfig =
        plotInstance.getCurrentPlotConfigurationClone().getDimensionConfig(PlotDimension.SHAPE);
    ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource);

    int seriesCount = valueSourceData.getSeriesDataForAllGroupCells().groupCellCount();

    // Loop all series and set series format.
    // Format based on dimension configs will be set later on in initFormatDelegate().
    for (int seriesIdx = 0; seriesIdx < seriesCount; ++seriesIdx) {
      // configure linestyle
      if (seriesFormat.getLineStyle() == LineStyle.NONE) {
        renderer.setSeriesLinesVisible(seriesIdx, false);
      } else {
        renderer.setSeriesLinesVisible(seriesIdx, true);
        renderer.setSeriesStroke(seriesIdx, seriesFormat.getStroke(), false);
      }

      // configure series shape if necessary
      if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, shapeDimensionConfig)) {
        if (seriesFormat.getItemShape() != ItemShape.NONE) {
          renderer.setSeriesShapesVisible(seriesIdx, true);
          renderer.setSeriesShape(seriesIdx, seriesFormat.getItemShape().getShape());
        } else {
          renderer.setSeriesShapesVisible(seriesIdx, false);
        }
      }

      // configure series color if necessary
      if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, colorDimensionConfig)) {
        Color itemColor = seriesFormat.getItemColor();
        renderer.setSeriesPaint(seriesIdx, itemColor);
        renderer.setSeriesFillPaint(seriesIdx, itemColor);
      }
      renderer.setSeriesOutlinePaint(seriesIdx, PlotConfiguration.DEFAULT_SERIES_OUTLINE_PAINT);
      renderer.setUseOutlinePaint(true);
    }
  }
    public PrecisionErrorChart() {
      super(new BorderLayout());
      timeseriescollectionPrecisionError = new TimeSeriesCollection();

      DateAxis dateaxis = new DateAxis("Time (hh:mm:ss)");
      dateaxis.setTickLabelFont(new Font("SansSerif", 0, 12));
      dateaxis.setLabelFont(new Font("SansSerif", 0, 14));
      dateaxis.setAutoRange(true);
      dateaxis.setUpperMargin(0.3D);
      dateaxis.setTickLabelsVisible(true);

      NumberAxis numberaxis = new NumberAxis("Precision error (ms)");
      numberaxis.setTickLabelFont(new Font("SansSerif", 0, 12));
      numberaxis.setLabelFont(new Font("SansSerif", 0, 14));
      numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
      numberaxis.setRangeWithMargins(-100.0, 100.0);

      XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(true, false);
      xylineandshaperenderer.setSeriesPaint(0, Color.blue);
      xylineandshaperenderer.setSeriesPaint(1, Color.red);
      xylineandshaperenderer.setSeriesPaint(2, Color.green);
      xylineandshaperenderer.setSeriesPaint(3, Color.pink);
      xylineandshaperenderer.setSeriesPaint(4, Color.magenta);
      xylineandshaperenderer.setSeriesPaint(5, Color.cyan);
      xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(0.7F, 0, 2));
      xylineandshaperenderer.setSeriesStroke(1, new BasicStroke(0.7F, 0, 2));
      xylineandshaperenderer.setBaseShapesVisible(true);

      XYPlot xyplot =
          new XYPlot(
              timeseriescollectionPrecisionError, dateaxis, numberaxis, xylineandshaperenderer);
      xyplot.setBackgroundPaint(Color.lightGray);
      xyplot.setDomainGridlinePaint(Color.white);
      xyplot.setRangeGridlinePaint(Color.white);
      xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
      xyplot.setDomainGridlinesVisible(true);

      JFreeChart jfreechart =
          new JFreeChart("Time Precision Error", new Font("SansSerif", 1, 24), xyplot, true);
      jfreechart.setBackgroundPaint(Color.white);
      ChartPanel chartpanel = new ChartPanel(jfreechart, true);
      add(chartpanel);
    }
Exemplo n.º 8
0
  protected void createChart(JPanel plotPanel, String xAxisName, String yAxisName) {
    JFreeChart chart =
        ChartFactory.createScatterPlot(
            null, null, null, null, PlotOrientation.VERTICAL, false, true, false);
    chart.setBorderVisible(true);

    chartPanel = new ChartPanel(chart, true, true, true, true, true);
    chartPanel.setAutoscrolls(true);
    chartPanel.setMouseZoomable(false);

    GridBagConstraints gbl_chartPanel = new GridBagConstraints();
    gbl_chartPanel.anchor = GridBagConstraints.CENTER;
    gbl_chartPanel.insets = new Insets(3, 3, 3, 3);
    gbl_chartPanel.weightx = 1.0;
    gbl_chartPanel.weighty = 1.0;
    gbl_chartPanel.fill = GridBagConstraints.BOTH;
    gbl_chartPanel.gridx = 0;
    gbl_chartPanel.gridy = 1;
    plotPanel.add(chartPanel, gbl_chartPanel);

    XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer();
    lineRenderer.setUseFillPaint(true);
    lineRenderer.setBaseToolTipGenerator(
        new StandardXYToolTipGenerator(
            StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
            new DecimalFormat("0.00"),
            new DecimalFormat("0.00")));

    Stroke stroke =
        new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f);
    lineRenderer.setSeriesStroke(0, stroke);
    lineRenderer.setSeriesPaint(0, Color.RED);
    lineRenderer.setSeriesShape(0, ShapeUtilities.createDiamond((float) 2.5));

    lineRenderer.setLegendItemLabelGenerator(
        new StandardXYSeriesLabelGenerator() {
          private static final long serialVersionUID = 7593430826693873496L;

          public String generateLabel(XYDataset dataset, int series) {
            XYSeries xys = ((XYSeriesCollection) dataset).getSeries(series);
            return xys.getDescription();
          }
        });

    NumberAxis xAxis = new NumberAxis(xAxisName);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisName);
    yAxis.setAutoRangeIncludesZero(false);

    XYSeriesCollection lineDataset = new XYSeriesCollection();

    XYPlot plot = chart.getXYPlot();
    plot.setRangePannable(true);
    plot.setDomainPannable(true);
    plot.setDomainGridlinePaint(Color.DARK_GRAY);
    plot.setRangeGridlinePaint(Color.DARK_GRAY);
    plot.setBackgroundPaint(new Color(224, 224, 224));

    plot.setDataset(0, lineDataset);
    plot.setRenderer(0, lineRenderer);
    plot.setDomainAxis(0, xAxis);
    plot.setRangeAxis(0, yAxis);
    plot.mapDatasetToDomainAxis(0, 0);
    plot.mapDatasetToRangeAxis(0, 0);

    LegendTitle legend = new LegendTitle(plot.getRenderer());
    legend.setItemFont(new Font("Arial", 0, 10));
    legend.setPosition(RectangleEdge.TOP);
    chart.addLegend(legend);
  }
Exemplo n.º 9
0
  /**
   * Creates a sample chart.
   *
   * @param dataset a dataset.
   * @return The chart.
   */
  private JFreeChart createChart(final XYDataset dataset) {

    // create the chart...
    final JFreeChart chart =
        ChartFactory.createXYLineChart(
            title, // chart title
            "Interval", // domain
            // axis
            // label
            "Mean Resp Time (s)", // "Average time (ms) taken for each service to complete", //
                                  // range
            // axis
            // label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
            );
    /*Shape[] arrayOfShape = new Shape[4];
      int[] arrayOfInt1 = { -3, 3, -3 };
      int[] arrayOfInt2 = { -3, 0, 3 };
      arrayOfShape[0] = new Polygon(arrayOfInt1, arrayOfInt2, 3);
      arrayOfShape[1] = new Rectangle2D.Double(-2.0D, -3.0D, 3.0D, 8.0D);
      arrayOfInt1 = new int[] { -3, 3, 3 };
      arrayOfInt2 = new int[] { 0, -3, 3 };
      arrayOfShape[2] = new Polygon(arrayOfInt1, arrayOfInt2, 3);
      arrayOfShape[3] = new Rectangle2D.Double(-6.0D, -6.0D, 6.0D, 6.0D);
      DefaultDrawingSupplier localDefaultDrawingSupplier = new DefaultDrawingSupplier(DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, arrayOfShape);
    */

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    // final StandardLegend legend = (StandardLegend) chart.getLegend();
    // legend.setDisplaySeriesShapes(true);
    // legend.setShapeScaleX(1.5);
    // legend.setShapeScaleY(1.5);
    // legend.setDisplaySeriesLines(true);

    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.black);
    XYLineAndShapeRenderer localLineAndShapeRenderer = (XYLineAndShapeRenderer) plot.getRenderer();
    localLineAndShapeRenderer.setBaseShapesVisible(true);
    // localLineAndShapeRenderer.setBaseItemLabelsVisible(true);
    localLineAndShapeRenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
    // customise the range axis...
    ValueAxis domain = (ValueAxis) plot.getDomainAxis();

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // rangeAxis.setTickUnit(new NumberTickUnit(20));
    rangeAxis.setAutoRangeIncludesZero(true);

    // ****************************************************************************
    // * JFREECHART DEVELOPER GUIDE *
    // * The JFreeChart Developer Guide, written by David Gilbert, is
    // available *
    // * to purchase from Object Refinery Limited: *
    // * *
    // * http://www.object-refinery.com/jfreechart/guide.html *
    // * *
    // * Sales are used to provide funding for the JFreeChart project -
    // please *
    // * support us so that we can continue developing free software. *
    // ****************************************************************************

    // customise the renderer...
    final XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    // renderer.setDrawShapes(true);
    renderer.setSeriesPaint(0, Color.red);
    renderer.setSeriesPaint(1, Color.blue);
    // renderer.setSeriesPaint(2, Color.orange);
    renderer.setSeriesPaint(2, Color.magenta);
    renderer.setSeriesPaint(3, Color.green);
    renderer.setSeriesPaint(4, Color.orange);
    renderer.setSeriesStroke(
        0,
        new BasicStroke(
            2.0f,
            BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_ROUND,
            1.0f,
            new float[] {1.0f, 1.0f},
            10.0f));
    renderer.setSeriesStroke(
        2,
        new BasicStroke(
            2.0f,
            BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_ROUND,
            1.0f,
            new float[] {1.0f, 1.0f},
            10.0f));
    renderer.setSeriesStroke(
        1,
        new BasicStroke(
            2.0f,
            BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_ROUND,
            1.0f,
            new float[] {1.0f, 1.0f},
            10.0f));
    renderer.setSeriesStroke(
        3,
        new BasicStroke(
            2.0f,
            BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_ROUND,
            1.0f,
            new float[] {1.0f, 1.0f},
            10.0f));
    renderer.setSeriesStroke(
        4,
        new BasicStroke(
            2.0f,
            BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_ROUND,
            1.0f,
            new float[] {1.0f, 1.0f},
            10.0f));
    // renderer.setSeriesShape(0, new Ellipse2D.Double(-3, -3, 6, 6));
    renderer.setSeriesShape(1, new Ellipse2D.Double(-3, -3, 6, 6));
    renderer.setSeriesShapesFilled(0, false);
    renderer.setSeriesShapesFilled(1, false);
    renderer.setSeriesShapesFilled(2, false);
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;
  }
  /**
   * @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();
  }
  private JFreeChart createChart() {

    // create the chart...
    JFreeChart chart =
        ChartFactory.createXYLineChart(
            null, // chart title
            null, // x axis label
            null, // y axis label
            null, // data
            PlotOrientation.VERTICAL,
            false, // include legend
            true, // tooltips
            false // urls
            );

    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customization...
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    // domain axis

    if ((indexAxis >= 0) && (!dataTable.isNominal(indexAxis))) {
      if ((dataTable.isDate(indexAxis)) || (dataTable.isDateTime(indexAxis))) {
        DateAxis domainAxis = new DateAxis(dataTable.getColumnName(indexAxis));
        domainAxis.setTimeZone(Tools.getPreferredTimeZone());
        chart.getXYPlot().setDomainAxis(domainAxis);
      }
    } else {
      plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits(Locale.US));
      ((NumberAxis) plot.getDomainAxis()).setAutoRangeStickyZero(false);
      ((NumberAxis) plot.getDomainAxis()).setAutoRangeIncludesZero(false);
    }
    ValueAxis xAxis = plot.getDomainAxis();
    if (indexAxis > -1) xAxis.setLabel(getDataTable().getColumnName(indexAxis));
    else xAxis.setLabel(SERIESINDEX_LABEL);
    xAxis.setAutoRange(true);
    xAxis.setLabelFont(LABEL_FONT_BOLD);
    xAxis.setTickLabelFont(LABEL_FONT);
    xAxis.setVerticalTickLabels(isLabelRotating());
    if (indexAxis > 0) {
      if (getRangeForDimension(indexAxis) != null) {
        xAxis.setRange(getRangeForDimension(indexAxis));
      }
    } else {
      if (getRangeForName(SERIESINDEX_LABEL) != null) {
        xAxis.setRange(getRangeForName(SERIESINDEX_LABEL));
      }
    }

    // renderer and range axis
    synchronized (dataTable) {
      int numberOfSelectedColumns = 0;
      for (int c = 0; c < dataTable.getNumberOfColumns(); c++) {
        if (getPlotColumn(c)) {
          if (dataTable.isNumerical(c)) {
            numberOfSelectedColumns++;
          }
        }
      }

      int columnCount = 0;
      for (int c = 0; c < dataTable.getNumberOfColumns(); c++) {
        if (getPlotColumn(c)) {
          if (dataTable.isNumerical(c)) {
            // YIntervalSeries series = new YIntervalSeries(this.dataTable.getColumnName(c));
            XYSeriesCollection dataset = new XYSeriesCollection();
            XYSeries series = new XYSeries(dataTable.getColumnName(c));
            Iterator<DataTableRow> i = dataTable.iterator();
            int index = 1;
            while (i.hasNext()) {
              DataTableRow row = i.next();
              double value = row.getValue(c);

              if ((indexAxis >= 0) && (!dataTable.isNominal(indexAxis))) {
                double indexValue = row.getValue(indexAxis);
                series.add(indexValue, value);
              } else {
                series.add(index++, value);
              }
            }
            dataset.addSeries(series);

            XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

            Color color = getColorProvider().getPointColor(1.0d);
            if (numberOfSelectedColumns > 1) {
              color =
                  getColorProvider()
                      .getPointColor(columnCount / (double) (numberOfSelectedColumns - 1));
            }
            renderer.setSeriesPaint(0, color);
            renderer.setSeriesStroke(
                0, new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
            renderer.setSeriesShapesVisible(0, false);

            NumberAxis yAxis = new NumberAxis(dataTable.getColumnName(c));
            if (getRangeForDimension(c) != null) {
              yAxis.setRange(getRangeForDimension(c));
            } else {
              yAxis.setAutoRange(true);
              yAxis.setAutoRangeStickyZero(false);
              yAxis.setAutoRangeIncludesZero(false);
            }
            yAxis.setLabelFont(LABEL_FONT_BOLD);
            yAxis.setTickLabelFont(LABEL_FONT);
            if (numberOfSelectedColumns > 1) {
              yAxis.setAxisLinePaint(color);
              yAxis.setTickMarkPaint(color);
              yAxis.setLabelPaint(color);
              yAxis.setTickLabelPaint(color);
            }

            plot.setRangeAxis(columnCount, yAxis);
            plot.setRangeAxisLocation(columnCount, AxisLocation.TOP_OR_LEFT);

            plot.setDataset(columnCount, dataset);
            plot.setRenderer(columnCount, renderer);
            plot.mapDatasetToRangeAxis(columnCount, columnCount);

            columnCount++;
          }
        }
      }
    }

    chart.setBackgroundPaint(Color.white);

    return chart;
  }
Exemplo n.º 12
0
  private JFreeChart createChart(XYDataset dataset, String title, String xTitle, String yTitle) {

    colors.add(Color.BLACK);
    colors.add(1, Color.BLUE);
    colors.add(1, Color.RED);
    colors.add(1, Color.GREEN);
    colors.add(1, Color.YELLOW);
    colors.add(1, Color.CYAN);
    colors.add(1, Color.MAGENTA);
    colors.add(1, new Color(111, 83, 64));
    colors.add(1, new Color(153, 51, 255));
    colors.add(1, new Color(102, 204, 255));
    colors.add(1, new Color(85, 80, 126));
    colors.add(1, new Color(168, 80, 126));

    chart =
        ChartFactory.createXYLineChart(
            title, xTitle, yTitle, dataset, PlotOrientation.VERTICAL, true, true, false);

    chart.setBackgroundPaint(Color.white);

    chart.getXYPlot().setBackgroundPaint(Color.white);
    chart.getXYPlot().setDomainGridlinePaint(Color.white);
    chart.getXYPlot().setRangeGridlinePaint(Color.white);

    int numSeries = series.getSeriesCount();

    XYLineAndShapeRenderer renderer = ((XYLineAndShapeRenderer) chart.getXYPlot().getRenderer());

    renderer.setDrawSeriesLineAsPath(true);

    renderer.setSeriesStroke(0, new BasicStroke(2.0F));

    renderer.setSeriesStroke(
        1,
        new BasicStroke(
            2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 1.0f, new float[] {2}, 0));

    renderer.setSeriesStroke(
        2,
        new BasicStroke(
            2.0f,
            BasicStroke.CAP_BUTT,
            BasicStroke.JOIN_BEVEL,
            1.0f,
            new float[] {6.0f, 2.0f, 6.0f, 2.0f},
            0.0f));

    renderer.setSeriesStroke(
        3,
        new BasicStroke(
            2.0f,
            BasicStroke.CAP_BUTT,
            BasicStroke.JOIN_BEVEL,
            1.0f,
            new float[] {12.0f, 2.0f, 2.0f, 2.0f},
            0.0f));

    renderer.setSeriesStroke(
        4,
        new BasicStroke(
            2.0f,
            BasicStroke.CAP_BUTT,
            BasicStroke.JOIN_BEVEL,
            1.0f,
            new float[] {12.0f, 2.0f, 2.0f, 2.0f, 2.0f, 2.0f},
            0.0f));

    renderer.setSeriesStroke(
        5,
        new BasicStroke(
            2.0f,
            BasicStroke.CAP_BUTT,
            BasicStroke.JOIN_BEVEL,
            1.0f,
            new float[] {12, 2, 12, 2, 2, 2, 2, 2, 2, 2, 2, 2},
            0));

    renderer.setSeriesStroke(
        6,
        new BasicStroke(
            2.0f,
            BasicStroke.CAP_BUTT,
            BasicStroke.JOIN_BEVEL,
            1.0f,
            new float[] {6.0f, 2.0f, 6.0f, 2.0f, 2.0f, 2.0f},
            0.0f));

    renderer.setSeriesStroke(
        7,
        new BasicStroke(
            2.0f,
            BasicStroke.CAP_BUTT,
            BasicStroke.JOIN_BEVEL,
            1.0f,
            new float[] {6.0f, 2.0f, 6.0f, 2.0f, 6.0f, 2.0f, 2.0f, 2.0f, 2.0f, 2.0f, 2.0f, 2.0f},
            0.0f));

    for (int i = 0; i < numSeries; i++) {

      if (i == colors.size()) {

        colors = addColors(colors, numSeries);
      }

      if (viewWithOutColor) {
        renderer.setSeriesPaint(i, Color.BLACK);
      } else {
        String name = series.getSeries(i).getKey().toString();

        if (!controlCurveColor.containsKey(name)) {
          renderer.setSeriesPaint(i, colors.get(i));
          controlCurveColor.put(name, colors.get(i));

        } else {

          renderer.setSeriesPaint(i, controlCurveColor.get(name));
        }

        renderer.setSeriesShapesVisible(i, viewPointsForm);

        if (viewWhiteBackground) {
          chart.getXYPlot().setBackgroundPaint(Color.WHITE);
        }
      }
    }
    chart.getXYPlot().setRenderer(renderer);

    return chart;
  }