protected JFreeChart createScatterChart() throws JRException {
   JFreeChart jfreeChart = super.createScatterChart();
   XYPlot xyPlot = (XYPlot) jfreeChart.getPlot();
   xyPlot.setDomainGridlinesVisible(false);
   XYLineAndShapeRenderer plotRenderer =
       (XYLineAndShapeRenderer) ((XYPlot) jfreeChart.getPlot()).getRenderer();
   plotRenderer.setBaseShapesFilled(false);
   plotRenderer.setBaseStroke(new BasicStroke(1f));
   return jfreeChart;
 }
Ejemplo n.º 2
0
  private static JFreeChart createDistributionViewChart() {
    XYPlot plot = new XYPlot();

    XYLineAndShapeRenderer dRenderer = new XYSplineRenderer();
    dRenderer.setBaseShapesVisible(false);
    dRenderer.setAutoPopulateSeriesPaint(false);
    dRenderer.setAutoPopulateSeriesStroke(false);
    dRenderer.setBaseStroke(TsCharts.getStrongStroke(LinesThickness.Thin));
    dRenderer.setDrawSeriesLineAsPath(true); // not sure if useful
    plot.setDataset(DISTRIBUTION_INDEX, Charts.emptyXYDataset());
    plot.setRenderer(DISTRIBUTION_INDEX, dRenderer);

    XYBarRenderer hRenderer = new XYBarRenderer();
    hRenderer.setShadowVisible(false);
    hRenderer.setDrawBarOutline(true);
    hRenderer.setAutoPopulateSeriesPaint(false);
    hRenderer.setAutoPopulateSeriesOutlinePaint(false);
    hRenderer.setBaseSeriesVisibleInLegend(false);
    plot.setDataset(HISTOGRAM_INDEX, Charts.emptyXYDataset());
    plot.setRenderer(HISTOGRAM_INDEX, hRenderer);

    NumberAxis domainAxis = new NumberAxis();
    domainAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setDomainAxis(domainAxis);
    plot.setDomainGridlinesVisible(false);

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    rangeAxis.setTickUnit(new NumberTickUnit(0.05));
    rangeAxis.setNumberFormatOverride(new DecimalFormat("0.###"));
    plot.setRangeAxis(rangeAxis);

    plot.mapDatasetToDomainAxis(0, 0);
    plot.mapDatasetToRangeAxis(0, 0);
    plot.mapDatasetToDomainAxis(1, 0);
    plot.mapDatasetToRangeAxis(1, 0);

    JFreeChart result = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    result.setPadding(TsCharts.CHART_PADDING);
    result.getTitle().setFont(TsCharts.CHART_TITLE_FONT);
    result.getLegend().setFrame(BlockBorder.NONE);
    result.getLegend().setBackgroundPaint(null);
    return result;
  }
  /**
   * 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);
  }
Ejemplo n.º 4
0
 private static JFreeChart createChart(XYDataset xydataset) {
   JFreeChart jfreechart =
       ChartFactory.createTimeSeriesChart(
           "Time Series Demo 7", "Date", "Value", xydataset, true, true, false);
   XYPlot xyplot = (XYPlot) jfreechart.getPlot();
   NumberAxis numberaxis = new NumberAxis(null);
   numberaxis.setAutoRangeIncludesZero(false);
   xyplot.setRangeAxis(1, numberaxis);
   java.util.List list = Arrays.asList(new Integer[] {new Integer(0), new Integer(1)});
   xyplot.mapDatasetToRangeAxes(0, list);
   XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
   xylineandshaperenderer.setAutoPopulateSeriesStroke(false);
   xylineandshaperenderer.setBaseStroke(new BasicStroke(1.5F, 1, 1));
   xylineandshaperenderer.setDrawSeriesLineAsPath(true);
   GeneralPath generalpath = new GeneralPath();
   generalpath.moveTo(-6F, 0.0F);
   generalpath.lineTo(-3F, 6F);
   generalpath.lineTo(3F, -6F);
   generalpath.lineTo(6F, 0.0F);
   xylineandshaperenderer.setLegendLine(generalpath);
   ChartUtilities.applyCurrentTheme(jfreechart);
   return jfreechart;
 }
Ejemplo n.º 5
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;
  }