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);
  }
  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 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);
    }
  }