ChartPanelShowStatistics(
      String title,
      String timeAxisLabel,
      String valueAxisLabel,
      XYDataset dataset /*, boolean legend, boolean tooltips, boolean urls*/) {
    this();
    // chart = ChartFactory.createTimeSeriesChart(title, timeAxisLabel, valueAxisLabel, dataset);
    chart = ChartFactory.createScatterPlot(title, timeAxisLabel, valueAxisLabel, dataset);
    ChartPanel p = new ChartPanel(chart);
    add(p, BorderLayout.CENTER);

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

    renderer.setBaseShapesVisible(false);
    //		renderer.setBaseShape(itemShape);	// 好像不管用,必须用setSeriesShape
    renderer.setBaseLinesVisible(true);
    //		renderer.setBasePaint(new Color(0));	// 好像不管用,必须用setSeriesPaint

    itemShape = ShapeUtilities.createDiamond((float) 3);
    renderer.setSeriesShape(0, itemShape);
    renderer.setSeriesPaint(0, new Color(255, 0, 0));

    renderer.setSeriesShape(1, itemShape);
    renderer.setSeriesPaint(1, new Color(0, 255, 0));

    renderer.setBaseToolTipGenerator(
        new StandardXYToolTipGenerator(
            "{0}:({1} , {2})",
            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"), new DecimalFormat("#.00")));
  }
  private void init() {
    timeSeriesList = new LinkedList<TimeSeries>();
    m_average = new TimeSeries(AVERANGE, Millisecond.class);
    m_tps = new TimeSeries(TPS, Millisecond.class);
    m_deviation = new TimeSeries(DEVIATION, Millisecond.class);
    stateMap.put(AVERANGE, m_average);
    stateMap.put(DEVIATION, m_deviation);
    stateMap.put(TPS, m_tps);
    timeSeriesList.add(m_average);
    timeSeriesList.add(m_tps);
    timeSeriesList.add(m_deviation);
    timeseriescollection = new TimeSeriesCollection();
    for (Iterator<TimeSeries> iterator = timeSeriesList.iterator(); iterator.hasNext(); ) {
      timeseriescollection.addSeries(iterator.next());
    }
    jfc =
        ChartFactory.createTimeSeriesChart(
            "Title", "unit", "yaxisName", timeseriescollection, true, true, false);
    // jfc.setTitle(new TextTitle("图表", new Font("黑体", Font.BOLD, 20)));
    // 取得统计图表
    XYPlot xyplot = jfc.getXYPlot();

    xylinerenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    xylinerenderer.setSeriesPaint(0, Color.BLUE);
    xylinerenderer.setSeriesPaint(1, Color.GREEN);
    xylinerenderer.setSeriesPaint(2, Color.RED);

    ValueAxis valueaxis = xyplot.getDomainAxis();
    valueaxis.setAutoRange(true);
    valueaxis.setFixedAutoRange(30000D);
    valueaxis = xyplot.getRangeAxis();
    chartPanel = new ChartPanel(jfc);
    chartPanel.setPreferredSize(new Dimension(600, 450));
  }
  /** 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;
  }
示例#4
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);
 }
  private void updateColor() {
    int len = timeseriescollection.getSeriesCount();
    if (len != 0) {
      for (int i = 0; i < len; i++) {
        TimeSeries t = timeseriescollection.getSeries(i);
        if (t.getKey().equals(AVERANGE)) {
          xylinerenderer.setSeriesPaint(i, Color.BLUE);
        } else if (t.getKey().equals(TPS)) {
          xylinerenderer.setSeriesPaint(i, Color.GREEN);
        } else if (t.getKey().equals(DEVIATION)) {
          xylinerenderer.setSeriesPaint(i, Color.RED);
        } else {

        }
      }
    }
  }
  /**
   * @param forecast
   * @param settings (next days)
   * @return
   */
  public JFreeChart createBarChart(
      final LiquidityForecast forecast, final LiquidityForecastSettings settings) {
    Validate.isTrue(settings.getNextDays() > 0 && settings.getNextDays() < 500);
    final LiquidityForecastCashFlow cashFlow =
        new LiquidityForecastCashFlow(forecast, settings.getNextDays());
    final TimeSeries accumulatedSeriesExpected =
        new TimeSeries(I18n.getString("plugins.liquidityplanning.forecast.expected"));
    final TimeSeries creditSeries =
        new TimeSeries(I18n.getString("plugins.liquidityplanning.common.credit"));
    final TimeSeries debitSeries =
        new TimeSeries(I18n.getString("plugins.liquidityplanning.common.debit"));
    double accumulatedExpected = settings.getStartAmount().doubleValue();

    final DayHolder dh = new DayHolder();
    final Date lower = dh.getDate();
    for (int i = 0; i < settings.getNextDays(); i++) {
      final Day day = new Day(dh.getDayOfMonth(), dh.getMonth() + 1, dh.getYear());
      if (i > 0) {
        accumulatedExpected +=
            cashFlow.getDebitsExpected()[i - 1].doubleValue()
                + cashFlow.getCreditsExpected()[i - 1].doubleValue();
      }
      accumulatedSeriesExpected.add(day, accumulatedExpected);
      creditSeries.add(day, cashFlow.getCreditsExpected()[i].doubleValue());
      debitSeries.add(day, cashFlow.getDebitsExpected()[i].doubleValue());
      dh.add(Calendar.DATE, 1);
    }
    dh.add(Calendar.DATE, -1);
    final XYChartBuilder cb =
        new XYChartBuilder(
            ChartFactory.createXYBarChart(
                null, null, false, null, null, PlotOrientation.VERTICAL, false, false, false));
    int counter = 0;

    final TimeSeriesCollection xyDataSeries = new TimeSeriesCollection();
    xyDataSeries.addSeries(accumulatedSeriesExpected);
    final XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer(true, true);
    lineRenderer.setSeriesPaint(0, cb.getRedMarker());
    lineRenderer.setSeriesVisibleInLegend(0, true);
    cb.setRenderer(counter, lineRenderer)
        .setDataset(counter++, xyDataSeries)
        .setStrongStyle(lineRenderer, false, accumulatedSeriesExpected);

    final TimeSeriesCollection cashflowSet = new TimeSeriesCollection();
    cashflowSet.addSeries(debitSeries);
    cashflowSet.addSeries(creditSeries);
    final XYBarRenderer barRenderer = new XYBarRenderer(.2);
    barRenderer.setSeriesPaint(0, cb.getGreenFill());
    barRenderer.setSeriesPaint(1, cb.getRedFill());
    barRenderer.setShadowVisible(false);
    cb.setRenderer(counter, barRenderer).setDataset(counter++, cashflowSet);

    cb.setDateXAxis(true).setDateXAxisRange(lower, dh.getDate()).setYAxis(true, null);
    return cb.getChart();
  }
  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);
  }
示例#8
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;
 }
示例#9
0
  @Override
  public JComponent getVisualisation(DataBean data) throws Exception {

    this.data = data;

    refreshAxisBoxes(data);

    List<Variable> vars = getFrame().getVariables();
    if (vars == null || vars.size() < 2) {
      if (xBox.getItemCount() >= 1) {
        xBox.setSelectedIndex(0);
      }
      if (yBox.getItemCount() >= 2) {
        yBox.setSelectedIndex(1);
      } else {
        yBox.setSelectedIndex(0);
      }
    } else {
      xBox.setSelectedItem(vars.get(0));
      yBox.setSelectedItem(vars.get(1));
    }

    xVar = (Variable) xBox.getSelectedItem();
    yVar = (Variable) yBox.getSelectedItem();

    PlotDescription description =
        new PlotDescription(data.getName(), xVar.getName(), yVar.getName());

    NumberAxis domainAxis = new NumberAxis(description.xTitle);
    domainAxis.setAutoRangeIncludesZero(false);
    NumberAxis rangeAxis = new NumberAxis(description.yTitle);
    rangeAxis.setAutoRangeIncludesZero(false);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setLinesVisible(false);
    renderer.setShapesVisible(true);
    renderer.setShape(new Ellipse2D.Float(-2, -2, 4, 4));
    renderer.setSeriesPaint(1, Color.black);

    plot = new XYPlot(new XYSeriesCollection(), domainAxis, rangeAxis, renderer);

    this.updateSelectionsFromApplication(false); // Calls also updateXYSerieses();

    JFreeChart chart = new JFreeChart(description.plotTitle, plot);

    application.addClientEventListener(this);

    selectableChartPanel = new SelectableChartPanel(chart, this);
    return selectableChartPanel;
  }
  public void setMin(float min) {
    for (int i = 0; i < minData.length; i++) {
      minData[i] = min;
    }

    XYSeriesCollection minCol = PlotingToolkit.getCollection(xData, minData, "Min");

    XYLineAndShapeRenderer minRender = new XYLineAndShapeRenderer(true, false);
    minRender.setSeriesPaint(0, Color.RED);

    previewPlot.getXYPlot().setRenderer(1, minRender);
    dataPlot.getXYPlot().setRenderer(1, minRender);

    dataPlot.getXYPlot().setDataset(1, minCol);
    previewPlot.getXYPlot().setDataset(1, minCol);
  }
  public void setMax(float max) {
    for (int i = 0; i < maxData.length; i++) {
      maxData[i] = max;
    }

    XYSeriesCollection maxCol = PlotingToolkit.getCollection(xData, maxData, "Max");

    XYLineAndShapeRenderer maxRender = new XYLineAndShapeRenderer(true, false);
    maxRender.setSeriesPaint(0, Color.MAGENTA);

    previewPlot.getXYPlot().setRenderer(2, maxRender);
    dataPlot.getXYPlot().setRenderer(2, maxRender);

    dataPlot.getXYPlot().setDataset(2, maxCol);
    previewPlot.getXYPlot().setDataset(2, maxCol);
  }
  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);
    }
  }
  /**
   * create the chart for the original time series
   *
   * @param tsData the data to plot.
   * @return a JFreeChart object of the chart
   */
  private void paintTheChart(double[] tsData) {

    // making the data
    //
    XYSeries dataset = new XYSeries("Series");
    for (int i = 0; i < tsData.length; i++) {
      dataset.add(i, (float) tsData[i]);
    }
    chartXYSeriesCollection = new XYSeriesCollection(dataset);

    // set the renderer
    //
    XYLineAndShapeRenderer xyRenderer = new XYLineAndShapeRenderer(true, false);
    xyRenderer.setSeriesPaint(0, new Color(0, 0, 0));
    xyRenderer.setBaseStroke(new BasicStroke(3));

    // X - the time axis
    //
    NumberAxis timeAxis = new NumberAxis("Time. (zoom: select with mouse; panning: Ctrl+mouse)");

    // Y axis
    //
    NumberAxis valueAxis = new NumberAxis("Values");
    valueAxis.setAutoRangeIncludesZero(false);

    // put these into collection of dots
    //
    this.timeseriesPlot = new XYPlot(chartXYSeriesCollection, timeAxis, valueAxis, xyRenderer);

    // enabling panning
    //
    this.timeseriesPlot.setDomainPannable(true);
    this.timeseriesPlot.setRangePannable(true);

    // finally, create the chart
    this.chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, timeseriesPlot, false);

    // set the progress listener to react to mouse clicks in the chart
    this.chart.addProgressListener(this);
  }
    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);
    }
示例#15
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;
  }
  /**
   * @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();
  }
  /**
   * Generates a chart in PNG format.
   *
   * @param outputFile the output file, it should exist.
   * @param pxWidth the image width in pixels.
   * @param pxHeight the image height in pixels.
   * @param chartTitle the chart title, may be null.
   * @param xAxisTitle the x axis title
   * @param yDataSeriesRange the axis range (null for auto)
   * @param yDataSeriesTitles the Y axis titles.
   * @param timeValuesInSeconds the time values in seconds
   * @param yDataSeries the Y axis value series.
   * @param yDataSeriesColors the Y axis value series drawing colors.
   * @param yDataSeriesTickSuffix TODO explain argument yDataSeriesTickSuffix
   * @param drawBorder draw, or not, the border.
   * @param backgroundColor the chart background color.
   */
  final void generatePngChart(
      File outputFile,
      int pxWidth,
      int pxHeight,
      String chartTitle,
      String xAxisTitle,
      String[] yDataSeriesTitles,
      double[] timeValuesInSeconds,
      double[][] yDataSeriesRange,
      double[][] yDataSeries,
      Color[] yDataSeriesColors,
      String[] yDataSeriesTickSuffix,
      boolean drawBorder,
      Color backgroundColor) {

    // Domain axis
    NumberAxis xAxis = new NumberAxis(xAxisTitle);
    xAxis.setFixedDimension(CHART_AXIS_DIMENSION);
    xAxis.setLabelPaint(Color.black);
    xAxis.setTickLabelPaint(Color.black);

    double maxSeconds = getMaxValue(timeValuesInSeconds);
    TimeAxisResolution xAxisRes = TimeAxisResolution.findTimeUnit(maxSeconds);
    xAxis.setTickUnit(new NumberTickUnit(xAxisRes.tickStep));
    double[] scaledTimeValues = xAxisRes.scale(timeValuesInSeconds);

    String tickSymbol =
        I18N.getString(locale, "running.job.details.chart.timeunit.symbol." + xAxisRes.name());
    xAxis.setNumberFormatOverride(new DecimalFormat("###.##'" + tickSymbol + "'"));

    // First dataset
    String firstDataSetTitle = yDataSeriesTitles[0];
    XYDataset firstDataSet = createXYDataSet(firstDataSetTitle, scaledTimeValues, yDataSeries[0]);
    Color firstDataSetColor = yDataSeriesColors[0];

    // First range axis
    NumberAxis firstYAxis = new NumberAxis(firstDataSetTitle);

    firstYAxis.setFixedDimension(CHART_AXIS_DIMENSION);
    setAxisRange(firstYAxis, yDataSeriesRange[0]);
    firstYAxis.setLabelPaint(firstDataSetColor);
    firstYAxis.setTickLabelPaint(firstDataSetColor);
    String firstAxisTickSuffix = yDataSeriesTickSuffix[0];
    if (firstAxisTickSuffix != null && !firstAxisTickSuffix.isEmpty()) {
      firstYAxis.setNumberFormatOverride(new DecimalFormat("###.##'" + firstAxisTickSuffix + "'"));
    }

    // Create the plot with domain axis and first range axis
    XYPlot plot = new XYPlot(firstDataSet, xAxis, firstYAxis, null);

    XYLineAndShapeRenderer firstRenderer = new XYLineAndShapeRenderer(true, false);
    plot.setRenderer(firstRenderer);

    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    firstRenderer.setSeriesPaint(0, firstDataSetColor);

    // Now iterate on next axes
    for (int i = 1; i < yDataSeries.length; i++) {
      // Create axis
      String seriesTitle = yDataSeriesTitles[i];
      Color seriesColor = yDataSeriesColors[i];
      NumberAxis yAxis = new NumberAxis(seriesTitle);

      yAxis.setFixedDimension(CHART_AXIS_DIMENSION);
      setAxisRange(yAxis, yDataSeriesRange[i]);

      yAxis.setLabelPaint(seriesColor);
      yAxis.setTickLabelPaint(seriesColor);

      String yAxisTickSuffix = yDataSeriesTickSuffix[i];
      if (yAxisTickSuffix != null && !yAxisTickSuffix.isEmpty()) {
        yAxis.setNumberFormatOverride(new DecimalFormat("###.##'" + yAxisTickSuffix + "'"));
      }

      // Create dataset and add axis to plot
      plot.setRangeAxis(i, yAxis);
      plot.setRangeAxisLocation(i, AxisLocation.BOTTOM_OR_LEFT);
      plot.setDataset(i, createXYDataSet(seriesTitle, scaledTimeValues, yDataSeries[i]));
      plot.mapDatasetToRangeAxis(i, i);
      XYItemRenderer renderer = new StandardXYItemRenderer();
      renderer.setSeriesPaint(0, seriesColor);
      plot.setRenderer(i, renderer);
    }

    // Create the chart
    JFreeChart chart = new JFreeChart(chartTitle, JFreeChart.DEFAULT_TITLE_FONT, plot, false);

    // Customize rendering
    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setBorderPaint(Color.BLACK);

    // Render image
    try {
      ChartUtilities.saveChartAsPNG(outputFile, chart, pxWidth, pxHeight);
    } catch (IOException e) {
      LOG.error("Chart export failed", e);
    }
  }
示例#18
0
 // configuramos las líneas de las series (añadimos un círculo en los puntos y asignamos el color
 // de cada serie)
 private void configurarRendered(XYLineAndShapeRenderer renderer) {
   renderer.setSeriesShapesVisible(0, false);
   // renderer.setSeriesShapesVisible(1, true);
   renderer.setSeriesPaint(0, COLOR_SERIE_1);
   // renderer.setSeriesPaint(1, COLOR_SERIE_2);
 }
  // --- GET HEIGTH GRAPH ------------------------------------------------------------------------
  private JFreeChart getHeightGraph() throws Exception {
    // get dataset
    String sGender = checkString(req.getParameter("gender"));
    final XYSeriesCollection dataset =
        getDataSet((sGender.equalsIgnoreCase("m") ? 1 : 2), "height-age-05-20.txt");

    // add patient data
    XYSeries patientSeries = new XYSeries("Patient", true, false);
    double height, lastPatientHeight = 0;
    float age;
    for (int i = 60; i < 240; i++) {
      height = getPatientHeightForAge(i);

      if (height > 0) {
        age = new Float(i).floatValue();
        patientSeries.add(age, new Float(height).floatValue());
        lastPatientHeight = height;
      }
    }

    dataset.addSeries(patientSeries);

    // create chart
    final JFreeChart chart =
        createChart(
            dataset,
            getTran("web", "heightForAgePercentiles"),
            getTran("web", "heightInCentimeter"));

    // add annotations
    XYPlot plot = chart.getXYPlot();
    java.awt.Font font = new java.awt.Font("SansSerif", Font.NORMAL, 9);

    int xPosAnnotation = 245;
    if (sGender.equalsIgnoreCase("m")) {
      // *** male ***
      addAnnotation("3rd", font, plot, xPosAnnotation, 163.00);
      addAnnotation("5th", font, plot, xPosAnnotation, 166.00);
      addAnnotation("25th", font, plot, xPosAnnotation, 172.00);
      addAnnotation("50th", font, plot, xPosAnnotation, 177.00);
      addAnnotation("75th", font, plot, xPosAnnotation, 182.00);
      addAnnotation("95th", font, plot, xPosAnnotation, 188.00);
      addAnnotation("97th", font, plot, xPosAnnotation, 191.00);
    } else {
      // *** female ***
      addAnnotation("3rd", font, plot, xPosAnnotation, 151.00);
      addAnnotation("5th", font, plot, xPosAnnotation, 154.00);
      addAnnotation("25th", font, plot, xPosAnnotation, 159.00);
      addAnnotation("50th", font, plot, xPosAnnotation, 163.00);
      addAnnotation("75th", font, plot, xPosAnnotation, 168.00);
      addAnnotation("95th", font, plot, xPosAnnotation, 174.00);
      addAnnotation("97th", font, plot, xPosAnnotation, 176.35);
    }

    // patient annotation
    XYTextAnnotation annotation =
        new XYTextAnnotation("Patient", xPosAnnotation, lastPatientHeight);
    annotation.setFont(font);
    annotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    annotation.setPaint(Color.BLUE);
    plot.addAnnotation(annotation);

    // visual customization
    chart.setBackgroundPaint(Color.WHITE);

    // series colors
    int idx = 0;
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesPaint(idx, Color.red); //  3rd
    renderer.setSeriesShapesVisible(idx++, false);
    renderer.setSeriesPaint(idx, Color.orange); //  5th
    renderer.setSeriesShapesVisible(idx++, false);
    renderer.setSeriesPaint(idx, Color.orange); // 25th
    renderer.setSeriesShapesVisible(idx++, false);
    renderer.setSeriesPaint(idx, Color.green); // 50th
    renderer.setSeriesShapesVisible(idx++, false);
    renderer.setSeriesPaint(idx, Color.orange); // 75th
    renderer.setSeriesShapesVisible(idx++, false);
    renderer.setSeriesPaint(idx, Color.orange); // 95th
    renderer.setSeriesShapesVisible(idx++, false);
    renderer.setSeriesPaint(idx, Color.red); // 97th
    renderer.setSeriesShapesVisible(idx++, false);
    renderer.setSeriesPaint(idx, Color.blue); // patient
    renderer.setSeriesShapesVisible(idx, true);

    // only dots for patient values
    renderer.setSeriesLinesVisible(idx, false); // no curve
    int dotSize = 3;
    renderer.setSeriesShape(
        idx, new Ellipse2D.Double(dotSize / 2.0 * (-1), dotSize / 2.0 * (-1), dotSize, dotSize));

    // labels
    renderer.setSeriesItemLabelGenerator(
        idx,
        new StandardXYItemLabelGenerator(
            "{2}", new DecimalFormat("0.00"), new DecimalFormat("0.00")));
    renderer.setSeriesItemLabelsVisible(idx, true);
    plot.setRenderer(renderer);

    return chart;
  }
  /** Displays the data in a graph. */
  private void showPlot() {
    // Create a data series containing the heading error data...
    XYSeries headingErrorSeries = new XYSeries("Heading Error");
    Enumeration<HeadingDivergenceState> e = divergenceData.elements();
    while (e.hasMoreElements()) {
      HeadingDivergenceState currState = e.nextElement();
      headingErrorSeries.add(
          (currState.time - robotData.getExpStartTime()) / 1000, currState.headingError);
    }

    // Create two data series one containing the times when the robot starts heading
    // towards a waypoint, and another containing the times when the robot arrives at
    // a waypoint
    final XYSeries beginEdgeSeries = new XYSeries("Begin Edge Traveral");
    final XYSeries waypointArrivalSeries = new XYSeries("Waypoint Arrival");
    Vector<PathEdge> pathEdges = robotData.getPathEdges();
    Enumeration<PathEdge> e2 = pathEdges.elements();
    while (e2.hasMoreElements()) {
      PathEdge currEdge = e2.nextElement();
      double beginEdgeTime = (currEdge.getStartTime() - robotData.getExpStartTime()) / 1000.0;
      beginEdgeSeries.add(beginEdgeTime, 0);
      double wayPointArrivalTime = (currEdge.getEndTime() - robotData.getExpStartTime()) / 1000.0;
      waypointArrivalSeries.add(wayPointArrivalTime, 0);
    }

    // Create a dataset out of the data series
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(headingErrorSeries);
    dataset.addSeries(beginEdgeSeries);
    dataset.addSeries(waypointArrivalSeries);

    // Create the chart
    JFreeChart chart =
        ChartFactory.createXYLineChart(
            "Heading Error vs. Time", // chart title
            "Time (s)", // x axis label
            "Heading Error (radians)", // y axis label
            dataset, // the data
            PlotOrientation.VERTICAL, // plot orientation (y axis is vertical)
            true, // include legend
            true, // tooltips
            false // urls
            );

    // Place the legend on top of the chart just below the title.
    LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.TOP);

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();
    //        plot.setBackgroundPaint(Color.lightGray);
    //    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    //        plot.setDomainGridlinePaint(Color.white);
    //        plot.setRangeGridlinePaint(Color.white);

    // Display the points and not the lines connecting the points
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, true); // display the heading errors as a line
    renderer.setSeriesShapesVisible(0, false);
    renderer.setSeriesLinesVisible(
        1, false); // display the begin edge traversal points as blue dots
    renderer.setSeriesShapesVisible(1, true);
    renderer.setSeriesPaint(1, Color.BLUE);
    renderer.setSeriesShape(1, new java.awt.geom.Ellipse2D.Double(-3, -3, 6, 6));
    renderer.setSeriesLinesVisible(
        2, false); // display the begin edge traversal points as green dots
    renderer.setSeriesShapesVisible(2, true);
    renderer.setSeriesPaint(2, Color.GREEN.darker());
    renderer.setSeriesShape(2, new java.awt.geom.Ellipse2D.Double(-5, -5, 10, 10));
    plot.setRenderer(renderer);

    //        final NumberAxis domainAxis = (NumberAxis)plot.getDomainAxis();
    //        domainAxis.setRange(new Range(0,140));

    //        final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    //     // change the auto tick unit selection to integer units only...
    ////        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    //        rangeAxis.setRange(new Range(-Math.PI, Math.PI));

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(1000, 600));

    // Create a frame for the chart, then display it.
    ApplicationFrame appFrame = new ApplicationFrame("Heading Error for " + logFileName);
    appFrame.setContentPane(chartPanel);
    appFrame.pack();
    RefineryUtilities.centerFrameOnScreen(appFrame);
    appFrame.setVisible(true);
  }
示例#21
0
  private static BufferedImage getChart(double[] tsData, double redDot) {
    try {

      // making the data
      //
      XYSeries dataset = new XYSeries("Series");
      for (int i = 0; i < tsData.length; i++) {
        dataset.add(i, (float) tsData[i]);
      }
      XYSeriesCollection chartXYSeriesCollection = new XYSeriesCollection(dataset);

      XYSeries dot = new XYSeries("Dot");
      dot.add((float) redDot, 0.0f);
      chartXYSeriesCollection.addSeries(dot);

      // set the renderer
      //
      XYLineAndShapeRenderer xyRenderer = new XYLineAndShapeRenderer(true, false);
      xyRenderer.setBaseStroke(new BasicStroke(3));

      xyRenderer.setSeriesPaint(0, new Color(0, 0, 0));
      xyRenderer.setSeriesLinesVisible(0, true);
      xyRenderer.setSeriesShapesVisible(0, false);

      xyRenderer.setSeriesPaint(1, Color.RED);
      xyRenderer.setSeriesLinesVisible(1, false);
      xyRenderer.setSeriesShapesVisible(1, true);

      // X - the time axis
      //
      NumberAxis timeAxis = new NumberAxis();
      timeAxis.setLabel("Time");

      // Y axis
      //
      NumberAxis valueAxis = new NumberAxis("Values");
      valueAxis.setAutoRangeIncludesZero(false);
      valueAxis.setLabel("Values");

      // put these into collection of dots
      //
      XYPlot timeseriesPlot = new XYPlot(chartXYSeriesCollection, timeAxis, valueAxis, xyRenderer);

      // finally, create the chart
      JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, timeseriesPlot, false);

      BufferedImage objBufferedImage = chart.createBufferedImage(800, 400);
      ByteArrayOutputStream bas = new ByteArrayOutputStream();
      try {
        ImageIO.write(objBufferedImage, "png", bas);
      } catch (IOException e) {
        e.printStackTrace();
      }
      byte[] byteArray = bas.toByteArray();

      InputStream in = new ByteArrayInputStream(byteArray);
      BufferedImage image = ImageIO.read(in);

      return image;
    } catch (IOException e) {
      e.printStackTrace();
    }
    return null;
  }
示例#22
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;
  }
示例#23
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);
  }
  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;
  }
  public void setAScan(float[] aData, int pos) {
    {
      if (aData.length != aScanData.length) {
        xData = new float[aData.length];
        maxData = new float[aData.length];
        minData = new float[aData.length];
      }

      for (int i = 0; i < xData.length; i++) {
        xData[i] = xDataMin + (xDataMax - xDataMin) * (i / ((float) xData.length - 1));
      }

      aScanData = aData;

      XYSeriesCollection datCol1 = PlotingToolkit.getCollection(xData, aScanData, "Data");

      XYSeriesCollection datCol2 =
          PlotingToolkit.getCollection(
              new float[] {xData[pos]}, new float[] {aScanData[pos]}, "Data");

      previewPlot.getXYPlot().setDataset(0, datCol1);
      previewPlot.getXYPlot().setDataset(3, datCol2);

      XYLineAndShapeRenderer dataRender1 = new XYLineAndShapeRenderer(true, false);
      XYLineAndShapeRenderer dataRender2 = new XYLineAndShapeRenderer(false, true);

      dataRender1.setSeriesPaint(0, Color.CYAN);
      dataRender2.setSeriesPaint(0, Color.RED);

      previewPlot.getXYPlot().setRenderer(0, dataRender1);
      previewPlot.getXYPlot().setRenderer(3, dataRender2);
    }

    /*
     * Log Data
     */
    {
      logData = aScanData.clone();

      for (int i = 0; i < logData.length; i++) {
        if (logData[i] < 0.0001f) {
          logData[i] += 0.0001f;
        }

        logData[i] = (float) Math.log(logData[i]);
      }

      XYSeriesCollection logCol = PlotingToolkit.getCollection(xData, logData, "Data");
      XYSeriesCollection datCol2 =
          PlotingToolkit.getCollection(
              new float[] {xData[pos]}, new float[] {logData[pos]}, "Data");

      dataPlot.getXYPlot().setDataset(0, logCol);
      dataPlot.getXYPlot().setDataset(3, datCol2);
      // Set the rendering
      XYLineAndShapeRenderer dataRender = new XYLineAndShapeRenderer(true, false);
      XYLineAndShapeRenderer dataRender2 = new XYLineAndShapeRenderer(false, true);
      dataRender2.setSeriesPaint(0, Color.RED);
      dataRender.setSeriesPaint(0, Color.CYAN);
      dataPlot.getXYPlot().setRenderer(0, dataRender);
      dataPlot.getXYPlot().setRenderer(3, dataRender2);
    }
  }
示例#26
0
package com.xuyuan.chart.jfreechart.helloworld;