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

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

Introduction

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

Prototype

@Override
public int getItemCount() 

Source Link

Document

Returns the number of items in the series.

Usage

From source file:edu.fullerton.viewerplugin.PluginSupport.java

public static void getRangeLimits(XYSeriesCollection mtds, Double[] rng, int skip, float xmin, float xmax) {
    Double minx, miny, maxx, maxy;

    minx = miny = Double.MAX_VALUE;

    maxx = maxy = -Double.MAX_VALUE;
    for (Iterator it = mtds.getSeries().iterator(); it.hasNext();) {

        XYSeries ds = (XYSeries) it.next();
        for (int item = skip; item < ds.getItemCount() - skip; item++) {
            double x = ds.getX(item).doubleValue();
            double y = ds.getY(item).doubleValue();

            if (x >= xmin && x <= xmax) {
                minx = Math.min(minx, x);
                miny = Math.min(miny, y);
                maxx = Math.max(maxx, x);
                maxy = Math.max(maxy, y);
            }//from w  ww.  j a v  a  2s  . co  m
        }
    }
    rng[0] = minx;
    rng[1] = miny;
    rng[2] = maxx;
    rng[3] = maxy;
}

From source file:edu.fullerton.viewerplugin.PluginSupport.java

public static int scaleRange(XYSeriesCollection mtds, Double miny, Double maxy) {
    int exp = PluginSupport.getExp(miny, maxy);
    if (exp > 0 && exp < 100) {
        int nseries = mtds.getSeriesCount();
        XYSeries[] newSeries = new XYSeries[nseries];

        double scale = Math.pow(10, exp);
        for (int s = 0; s < nseries; s++) {
            XYSeries ds = (XYSeries) mtds.getSeries(s);
            Comparable skey = mtds.getSeriesKey(s);
            XYSeries nds = new XYSeries(skey, true);
            for (int item = 0; item < ds.getItemCount(); item++) {
                double x = ds.getX(item).doubleValue();
                double y = ds.getY(item).doubleValue();

                y *= scale;/*from   ww w  . java  2 s.  com*/
                nds.add(x, y);
            }
            newSeries[s] = nds;
        }
        mtds.removeAllSeries();
        for (int s = 0; s < nseries; s++) {
            mtds.addSeries(newSeries[s]);
        }
    } else {
        exp = 0;
    }
    return exp;
}

From source file:net.sf.mzmine.chartbasics.HistogramChartFactory.java

/**
 * Performs Gaussian fit on XYSeries/*from w  w  w  . j a v  a 2 s  .  com*/
 * 
 * @param series the data
 * @param gMin lower bound of Gaussian fit
 * @param gMax upper bound of Gaussian fit
 * @param sigDigits number of significant digits
 * @return double[] {normFactor, mean, sigma} as a result of
 *         GaussianCurveFitter.create().fit(obs.toList())
 */
public static double[] gaussianFit(XYSeries series, double gMin, double gMax) {
    // gaussian fit
    WeightedObservedPoints obs = new WeightedObservedPoints();

    for (int i = 0; i < series.getItemCount(); i++) {
        double x = series.getX(i).doubleValue();
        if (x >= gMin && x <= gMax)
            obs.add(x, series.getY(i).doubleValue());
    }

    return fitter.fit(obs.toList());
}

From source file:net.sf.mzmine.chartbasics.HistogramChartFactory.java

/**
 * Adds a Gaussian curve to the plot//from w  w  w . jav  a2 s  .  c om
 * 
 * @param plot
 * @param series the data
 * @param gMin lower bound of Gaussian fit
 * @param gMax upper bound of Gaussian fit
 * @param sigDigits number of significant digits
 * @return
 */
public static double[] addGaussianFit(XYPlot plot, XYSeries series, double gMin, double gMax, int sigDigits,
        boolean annotations) {
    double[] fit = gaussianFit(series, gMin, gMax);
    double minval = series.getX(0).doubleValue();
    double maxval = series.getX(series.getItemCount() - 1).doubleValue();
    return addGaussianFit(plot, fit, minval, maxval, gMin, gMax, sigDigits, annotations);
}

From source file:domainhealth.frontend.graphics.JFreeChartGraphImpl.java

/**
 * Check to see if current graph has empty chart lines (ie. no data-series
 * in any lines), and if so, write the text 'NO DATA' in large letters 
 * across the front of the graph//from www  .  java  2  s.  c o m
 * 
 * @param graphImage The current image representation of the generated graph
 */
@SuppressWarnings("unchecked")
private void addNoDataLogoIfEmpty(BufferedImage graphImage) {
    int maxStatCount = 0;
    List<XYSeries> seriesList = xySeriesCollection.getSeries();

    for (XYSeries series : seriesList) {
        maxStatCount = Math.max(maxStatCount, series.getItemCount());
    }

    if (maxStatCount <= 0) {
        Graphics2D graphics2D = get2DGraphics(graphImage);
        graphics2D.setFont(new Font(GRAPH_TEXT_FONT, Font.PLAIN, 36));
        graphics2D.drawString(NO_DATA_TEXT, 200, 210);
        graphics2D.dispose();
    } else if (maxStatCount <= 1) {
        Graphics2D graphics2D = get2DGraphics(graphImage);
        graphics2D.setFont(new Font(GRAPH_TEXT_FONT, Font.PLAIN, 22));
        graphics2D.drawString(WAITING_FOR_DATA_TEXT_LN1, 152, 205);
        graphics2D.dispose();
        graphics2D = get2DGraphics(graphImage);
        graphics2D.setFont(new Font(GRAPH_TEXT_FONT, Font.PLAIN, 15));
        graphics2D.drawString(WAITING_FOR_DATA_TEXT_LN2, 81, 225);
        graphics2D.dispose();
    }
}

From source file:sim.util.media.chart.TimeSeriesAttributes.java

/** Clears the existing internal XYSeries, then adds all the series elements in the provided XYSeries to the
internal XYSeries.  Does not notify the chart to update.
*//*from w  w  w. j av a2 s . c  o  m*/
public void setSeries(XYSeries series) {
    this.series.clear();
    int count = series.getItemCount();
    for (int i = 0; i < count; i++)
        this.series.add(series.getDataItem(i), true);
}

From source file:edu.gmu.cs.sim.util.media.chart.TimeSeriesAttributes.java

/** Clears the existing internal XYSeries, then adds all the series elements in the provided XYSeries to the
 internal XYSeries.  Does not notify the chart to update.
 *///from   ww  w  .  java2  s .  co m
public void setSeries(XYSeries series) {
    this.series.clear();
    int count = series.getItemCount();
    for (int i = 0; i < count; i++) {
        this.series.add(series.getDataItem(i), true);
    }
}

From source file:com.jbombardier.console.charts.XYTimeChartPanel.java

@SuppressWarnings("unchecked")
public void removeOldDataPoints() {
    List<XYSeries> series = xyseriescollection.getSeries();
    for (XYSeries xySeries : series) {
        while (xySeries.getItemCount() > 0) {
            XYDataItem xyDataItem = xySeries.getDataItem(0);
            long itemTime = xyDataItem.getX().longValue();
            if (mostRecentTimeValue - timePeriod > itemTime) {
                xySeries.remove(0);/*from  w  w w .  j a  va2s  . c om*/
            } else {
                // Fast exit, the items will be in time order
                break;
            }
        }
    }
}

From source file:org.fhcrc.cpl.toolbox.gui.chart.PanelWithScatterPlot.java

/**
 * This method only does anything if there's exactly one series in the dataset.
 *
 * Performs linear regression, and then plots a regression line, from the
 * minimum to the maximum X value of the series.
 *
 * Removes the old series, adds this new one, and then adds the old one again,
 * so the regression line will appear on top. 
 *//*from   w  w  w . j  a va  2s.  c  om*/
public double[] addRegressionLine(int seriesIndex, boolean robustRegression) {
    if (dataset == null || dataset.getSeriesCount() < seriesIndex + 1)
        return null;
    XYSeries series = dataset.getSeries(seriesIndex);
    int n = series.getItemCount();
    double[] xValues = new double[n];
    double[] yValues = new double[n];

    double maxX = Double.MIN_VALUE;
    double minX = Double.MAX_VALUE;

    for (int i = 0; i < n; i++) {
        XYDataItem dataItem = series.getDataItem(i);
        xValues[i] = dataItem.getX().doubleValue();
        yValues[i] = dataItem.getY().doubleValue();

        if (xValues[i] > maxX)
            maxX = xValues[i];
        if (xValues[i] < minX)
            minX = xValues[i];
    }

    _log.debug("addRegressionLine, minX = " + minX + ", maxX = " + maxX);

    RegressionUtilities.robustRegression(xValues, yValues);
    double[] regressionCoefficients = null;
    if (robustRegression)
        regressionCoefficients = RegressionUtilities.robustRegression(xValues, yValues);
    else
        regressionCoefficients = MatrixUtil.linearRegression(xValues, yValues);
    _log.debug("addRegressionLine, coeffs = " + regressionCoefficients[0] + ", " + regressionCoefficients[1]);

    addLine(regressionCoefficients[1], regressionCoefficients[0], minX, maxX);

    return regressionCoefficients;
}

From source file:edu.fullerton.viewerplugin.TsPlot.java

private XYSeries LinFit(XYSeries ts) {
    XYSeries ret = new XYSeries("lin fit", false);

    int n = ts.getItemCount();
    double[] x = new double[n];
    double[] y = new double[n];
    XYDataItem it;//w  w  w  .  j  a va 2s  .c o  m
    for (int i = 0; i < n; i++) {
        it = ts.getDataItem(i);
        x[i] = it.getXValue();
        y[i] = it.getYValue();
    }
    LinearRegression lr = new LinearRegression(x, y);
    double b = lr.getIntercept();
    double m = lr.getSlope();
    double fit, t;
    for (int i = 0; i < n; i++) {

        it = ts.getDataItem(i);
        t = it.getXValue();
        fit = m * t + b;

        ret.add(t, fit);
    }

    return ret;
}