/**
   * Export chart values to a csv file
   *
   * @param file CSV file
   */
  private void export(File file) {
    String registro;
    int n = 0;
    int ne = 0;
    String cabecera = "Time;";
    for (int i = 0; i < plot.getDatasetCount(); i++) {
      XYSeriesCollection ds = (XYSeriesCollection) plot.getDataset(i);
      for (int j = 0; j < ds.getSeriesCount(); j++) {
        n++;
        XYSeries s = (XYSeries) ds.getSeries(j);
        cabecera += s.getKey().toString() + ";";
        if (n == 1) {
          ne = s.getItemCount();
        }
      }
    }
    String[][] exportacion = new String[ne][n + 1];
    n = 0;
    for (int i = 0; i < plot.getDatasetCount(); i++) {
      XYSeriesCollection ds = (XYSeriesCollection) plot.getDataset(i);
      for (int j = 0; j < ds.getSeriesCount(); j++) {
        XYSeries s = (XYSeries) ds.getSeries(j);
        n++;
        for (int e = 0; e < ne; e++) {
          try {
            exportacion[e][n] = ordinateFormat.format(s.getDataItem(e).getYValue());
          } catch (Exception ex) {
            exportacion[e][n] = "";
          }
          if (n == 1) {

            exportacion[e][0] = abcissaFormat.format(s.getDataItem(e).getXValue());
          }
        }
      }
    }
    FileWriter fichero;

    PrintWriter pw;

    try {
      fichero = new FileWriter(file.getAbsolutePath(), false);
      pw = new PrintWriter(fichero);
      pw.println(cabecera);
      for (String[] exp : exportacion) {
        String strRegistro = "";
        for (String e : exp) {
          strRegistro += e + ";";
        }
        pw.println(strRegistro);
      }

      pw.close();
    } catch (IOException ex) {
      Global.info.log(ex);
    }
  }
  @SuppressWarnings("rawtypes")
  @Override
  public void zoom(Rectangle selection) {
    if (map == null || layer == null) {
      return;
    }
    Set<FeatureId> selected = new HashSet<FeatureId>();
    try {
      XYSeriesCollection ds = (XYSeriesCollection) getChart().getXYPlot().getDataset(2);
      XYSeries selectionSeries = ds.getSeries(0);
      selectionSeries.clear();

      EntityCollection entities = this.getChartRenderingInfo().getEntityCollection();
      Iterator iter = entities.iterator();
      while (iter.hasNext()) {
        ChartEntity entity = (ChartEntity) iter.next();
        if (entity instanceof XYItemEntity) {
          XYItemEntity item = (XYItemEntity) entity;
          if (item.getSeriesIndex() != 0) {
            continue;
          }

          java.awt.Rectangle bound = item.getArea().getBounds();
          if (selection.intersects(bound.x, bound.y, bound.width, bound.height)) {
            XYSeriesCollection dataSet = (XYSeriesCollection) item.getDataset();
            XYSeries xySeries = dataSet.getSeries(item.getSeriesIndex());
            XYDataItem xyDataItem = xySeries.getDataItem(item.getItem());
            if (xyDataItem instanceof XYDataItem2) {
              XYDataItem2 dataItem = (XYDataItem2) xyDataItem;
              selectionSeries.add(dataItem);
              selected.add(ff.featureId(dataItem.getFeature().getID()));
            }
          }
        }
      }
    } catch (Exception e) {
      // skip
    } finally {
      if (selected.size() > 0) {
        map.select(ff.id(selected), layer);
      } else {
        map.select(Filter.EXCLUDE, layer);
      }
      this.forceRedraw();
    }
  }
 private XYIntervalSeries computeAcceptableDeviationData(double lowerBound, double upperBound) {
   final XYSeries identity =
       DatasetUtilities.sampleFunction2DToSeries(x -> x, lowerBound, upperBound, 100, "1:1 line");
   final XYIntervalSeries xyIntervalSeries = new XYIntervalSeries(identity.getKey());
   for (int i = 0; i < identity.getItemCount(); i++) {
     XYDataItem item = identity.getDataItem(i);
     final double x = item.getXValue();
     final double y = item.getYValue();
     if (scatterPlotModel.showAcceptableDeviation) {
       final double acceptableDeviation = scatterPlotModel.acceptableDeviationInterval;
       final double xOff = acceptableDeviation * x / 100;
       final double yOff = acceptableDeviation * y / 100;
       xyIntervalSeries.add(x, x - xOff, x + xOff, y, y - yOff, y + yOff);
     } else {
       xyIntervalSeries.add(x, x, x, y, y, y);
     }
   }
   return xyIntervalSeries;
 }
 private XYIntervalSeries computeRegressionData(double xStart, double xEnd) {
   if (scatterpointsDataset.getItemCount(0) > 1) {
     final double[] coefficients = Regression.getOLSRegression(scatterpointsDataset, 0);
     final Function2D curve = new LineFunction2D(coefficients[0], coefficients[1]);
     final XYSeries regressionData =
         DatasetUtilities.sampleFunction2DToSeries(curve, xStart, xEnd, 100, "regression line");
     final XYIntervalSeries xyIntervalRegression = new XYIntervalSeries(regressionData.getKey());
     for (int i = 0; i < regressionData.getItemCount(); i++) {
       XYDataItem item = regressionData.getDataItem(i);
       final double x = item.getXValue();
       final double y = item.getYValue();
       xyIntervalRegression.add(x, x, x, y, y, y);
     }
     return xyIntervalRegression;
   } else {
     JOptionPane.showMessageDialog(
         this,
         "Unable to compute regression line.\n"
             + "At least 2 values are needed to compute regression coefficients.");
     return null;
   }
 }
Example #5
0
  /**
   * Returns the y-value for the specified series and item.
   *
   * @param series the series (zero-based index).
   * @param index the index of the item of interest (zero-based).
   * @return The value (possibly <code>null</code>).
   */
  public Number getY(int series, int index) {

    XYSeries ts = (XYSeries) this.data.get(series);
    XYDataItem xyItem = ts.getDataItem(index);
    return xyItem.getY();
  }
 /**
  * Returns the x-value for the specified series and item.
  *
  * @param series the series (zero-based index).
  * @param item the item (zero-based index).
  * @return The x-value for the specified series and item.
  */
 public Number getX(int series, int item) {
   XYSeries s = (XYSeries) this.data.get(series);
   XYDataItem dataItem = s.getDataItem(item);
   return dataItem.getX();
 }