Example usage for org.jfree.data.xy XYSeries createCopy

List of usage examples for org.jfree.data.xy XYSeries createCopy

Introduction

In this page you can find the example usage for org.jfree.data.xy XYSeries createCopy.

Prototype

public XYSeries createCopy(int start, int end) throws CloneNotSupportedException 

Source Link

Document

Creates a new series by copying a subset of the data in this time series.

Usage

From source file:org.micromanager.asidispim.fit.Fitter.java

/**
 * Given a JFreeChart dataset and a commons math function, return a JFreeChart
 * dataset in which the original x values are now accompanied by the y values
 * predicted by the function//ww  w. jav  a2 s .c  o  m
 * 
 * @param data input JFreeChart data set
 * @param type one of the Fitter.FunctionType predefined functions
 * @param parms parameters describing the function.  These need to match the
 *             selected function or an IllegalArgumentEception will be thrown
 * 
 * @return JFreeChart dataset with original x values and fitted y values.
 */
public static XYSeries getFittedSeries(XYSeries data, FunctionType type, double[] parms) {
    XYSeries result = new XYSeries(data.getItemCount() * 10);
    double minRange = data.getMinX();
    double maxRange = data.getMaxX();
    double xStep = (maxRange - minRange) / (data.getItemCount() * 10);
    switch (type) {
    case NoFit:
        try {
            result = data.createCopy(0, data.getItemCount() - 1);
            result.setKey(data.getItemCount() * 10);
        } catch (CloneNotSupportedException ex) {
            return null;
        }
        break;
    case Pol1:
    case Pol2:
    case Pol3:
        checkParms(type, parms);
        PolynomialFunction polFunction = new PolynomialFunction(parms);
        for (int i = 0; i < data.getItemCount() * 10; i++) {
            double x = minRange + i * xStep;
            double y = polFunction.value(x);
            result.add(x, y);
        }
        break;
    case Gaussian:
        checkParms(type, parms);
        Gaussian.Parametric gf = new Gaussian.Parametric();
        for (int i = 0; i < data.getItemCount() * 10; i++) {
            double x = minRange + i * xStep;
            double[] gparms = new double[3];
            System.arraycopy(parms, 0, gparms, 0, 3);
            double y = gf.value(x, gparms) + parms[3];
            result.add(x, y);
        }
        break;
    }

    return result;
}

From source file:org.micromanager.saim.fit.Fitter.java

/**
 * Given a JFreeChart dataset and a commons math function, return a JFreeChart
 * dataset in which the original x values are now accompanied by the y values
 * predicted by the function//  w  w w.jav  a 2s . c o m
 * 
 * @param data input JFreeChart data set
 * @param type one of the Fitter.FunctionType predefined functions
 * @param parms parameters describing the function.  These need to match the
 *             selected function or an IllegalArgumentEception will be thrown
 * 
 * @return JFreeChart dataset with original x values and fitted y values.
 */
public static XYSeries getFittedSeries(XYSeries data, FunctionType type, double[] parms) {

    XYSeries result = new XYSeries((String) data.getKey() + "-Fit", false, true);
    double minRange = data.getMinX();
    double maxRange = data.getMaxX();
    double xStep = (maxRange - minRange) / (data.getItemCount() * 10);
    switch (type) {
    case NoFit: {
        try {
            XYSeries resCopy = data.createCopy(0, data.getItemCount() - 1);
            return resCopy;
        } catch (CloneNotSupportedException ex) {
            return null;
        }
    }
    case Pol1:
    case Pol2:
    case Pol3:
        checkParms(type, parms);
        PolynomialFunction polFunction = new PolynomialFunction(parms);
        for (int i = 0; i < data.getItemCount() * 10; i++) {
            double x = minRange + i * xStep;
            double y = polFunction.value(x);
            result.add(x, y);
        }
        break;
    case Gaussian:
        checkParms(type, parms);
        Gaussian.Parametric gf = new Gaussian.Parametric();
        for (int i = 0; i < data.getItemCount() * 10; i++) {
            double x = minRange + i * xStep;
            double[] gparms = new double[3];
            System.arraycopy(parms, 0, gparms, 0, 3);
            double y = gf.value(x, gparms) + parms[3];
            result.add(x, y);
        }
        break;
    }

    return result;
}