Example #1
0
  private boolean plotCorrectionData() {
    plot3d.removeAllPlots();
    XYSeries series;
    XYPlot plot = chartPanel.getChart().getXYPlot();
    XYSeriesCollection lineDataset = (XYSeriesCollection) plot.getDataset(0);
    DecimalFormat df = new DecimalFormat(".00");
    String val;
    int i = 0;
    int j = 0;
    if (!Utils.isTableEmpty(corrTable)) {
      try {
        for (i = 1; i < corrTable.getColumnCount(); ++i) {
          val = corrTable.getValueAt(0, i).toString();
          series = new XYSeries(df.format(Double.valueOf(val)));
          for (j = 1; j < corrTable.getRowCount(); ++j) {
            if (corrTable.getValueAt(j, i) != null) {
              val = corrTable.getValueAt(j, i).toString();
              if (!val.isEmpty())
                series.add(
                    Double.valueOf(corrTable.getValueAt(j, 0).toString()), Double.valueOf(val));
            }
          }
          if (series.getItemCount() > 0) {
            corrData.add(series);
            series.setDescription(series.getKey().toString());
            lineDataset.addSeries(series);
          }
        }
        plot.getDomainAxis(0).setAutoRange(true);
        plot.getRangeAxis(0).setAutoRange(true);
        plot.getDomainAxis(0).setLabel(xAxisName);
        plot.getRangeAxis(0).setLabel(yAxisName);
        plot.getRenderer(0).setSeriesVisible(0, false);

        double[] x = new double[xAxisArray.size()];
        for (i = 0; i < xAxisArray.size(); ++i) x[i] = xAxisArray.get(i);
        double[] y = new double[yAxisArray.size()];
        for (i = 0; i < yAxisArray.size(); ++i) y[i] = yAxisArray.get(i);
        double[][] z = Utils.doubleZArray(corrTable, x, y);
        Color[][] colors = Utils.generateTableColorMatrix(corrTable, 1, 1);
        plot3d.addGridPlot("Average Error % Plot", colors, x, y, z);
      } catch (NumberFormatException e) {
        logger.error(e);
        JOptionPane.showMessageDialog(
            null,
            "Error parsing number from "
                + corrTableName
                + " table, cell("
                + i
                + " : "
                + j
                + "): "
                + e,
            "Error",
            JOptionPane.ERROR_MESSAGE);
        return false;
      }
    }
    return true;
  }
 /**
  * Clear a series
  *
  * @param seriesName Name of series to clear
  */
 public void clear(String seriesName) {
   for (XYSeries serie : seriesList) {
     if (serie.getKey().toString().equals(seriesName)) {
       serie.clear();
       break;
     }
   }
 }
  /**
   * 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);
    }
  }
 /**
  * Add sample to a series
  *
  * @param x Abcissa
  * @param y Ordinate
  * @param seriesName Series name
  */
 @Override
 public void addSample(double x, double y, String seriesName) {
   for (XYSeries serie : seriesList) {
     if (serie.getKey().toString().equals(seriesName)) {
       serie.add(x, y);
       break;
     }
   }
 }
 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;
   }
 }
 /** Returns the name of the signal (the one which will be displaied in the signal display. */
 public String getName() {
   String name = data.getKey().toString();
   return name;
 }