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

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

Introduction

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

Prototype

public Number getX(int index) 

Source Link

Document

Returns the x-value at the specified index.

Usage

From source file:audio.cords.old.RegressionDemo.java

private static XYDataset regress(XYSeriesCollection data) {
    // Determine bounds
    double xMin = Double.MAX_VALUE, xMax = 0;
    for (int i = 0; i < data.getSeriesCount(); i++) {
        XYSeries ser = data.getSeries(i);
        for (int j = 0; j < ser.getItemCount(); j++) {
            double x = ser.getX(j).doubleValue();
            if (x < xMin) {
                xMin = x;/* w w  w.  j a  v a 2s . c  o  m*/
            }
            if (x > xMax) {
                xMax = x;
            }
        }
    }
    // Create 2-point series for each of the original series
    XYSeriesCollection coll = new XYSeriesCollection();
    for (int i = 0; i < data.getSeriesCount(); i++) {
        XYSeries ser = data.getSeries(i);
        int n = ser.getItemCount();
        double sx = 0, sy = 0, sxx = 0, sxy = 0, syy = 0;
        for (int j = 0; j < n; j++) {
            double x = ser.getX(j).doubleValue();
            double y = ser.getY(j).doubleValue();
            sx += x;
            sy += y;
            sxx += x * x;
            sxy += x * y;
            syy += y * y;
        }
        double b = (n * sxy - sx * sy) / (n * sxx - sx * sx);
        double a = sy / n - b * sx / n;
        XYSeries regr = new XYSeries(ser.getKey());
        regr.add(xMin, a + b * xMin);
        regr.add(xMax, a + b * xMax);
        coll.addSeries(regr);
    }
    return coll;
}

From source file:e3fraud.gui.GraphingTool.java

public static JFreeChart generateGraph(E3Model model, Resource need, int startValue, int endValue,
        boolean expected) {
    //Get list of actors
    Set<Resource> actors = model.getActors();
    //generate a series
    Map<Resource, XYSeries> actorSeriesMap = model.getTotalForActors(need, startValue, endValue, expected);

    //for each actor
    XYSeriesCollection line_chart_dataset = new XYSeriesCollection();

    for (Resource actor : actors) {
        //add it's series to the chart
        XYSeries series = actorSeriesMap.get(actor);
        line_chart_dataset.addSeries(series);
        double slope;
        if (series.getItemCount() > 1) {
            slope = (series.getY(0).doubleValue() - series.getY(1).doubleValue())
                    / (series.getX(0).doubleValue() - series.getX(1).doubleValue());
        } else {//from ww w  .j a  va  2s  . co  m
            slope = 0;
        }
        DecimalFormat df = new DecimalFormat("#.##");
        series.setKey(series.getKey() + "\nAvg.\t = \t" + df.format(model.getLastKnownAverages().get(actor))
                + "\nSlope\t = \t" + df.format(slope));
    }

    /* Step -2:Define the JFreeChart object to create line chart */
    JFreeChart lineChartObject;
    if (expected) {
        lineChartObject = ChartFactory.createScatterPlot(
                "(Ideal) Profit Vs Occurences of \"" + need.getProperty(E3value.e3_has_name).getString()
                        + " \"",
                "Occurences of \"" + need.getProperty(E3value.e3_has_name).getString() + " \"",
                "Profit (in Euro)", line_chart_dataset, PlotOrientation.VERTICAL, true, true, false);
    } else {
        lineChartObject = ChartFactory.createScatterPlot(
                "(Non-ideal) Profit Vs Occurences of \"" + need.getProperty(E3value.e3_has_name).getString()
                        + " \"",
                "Occurences of \"" + need.getProperty(E3value.e3_has_name).getString() + " \"",
                "Profit (in Euro)", line_chart_dataset, PlotOrientation.VERTICAL, true, true, false);
    }
    return lineChartObject;
}

From source file:org.fhcrc.cpl.viewer.mrm.Utils.java

public static float[][] PDStoArray(PlotDataSupplier pds) {
    float retval[][] = null;
    if (pds == null)
        return retval;
    XYSeries xys = pds.getGraphData();
    int itemCount = xys.getItemCount();
    retval = new float[2][itemCount];
    for (int i = 0; i < itemCount; i++) {
        retval[0][i] = xys.getX(i).floatValue();
        Number y = xys.getY(i);/*from  w  w  w.j av  a2 s.  co m*/
        if (y != null) {
            retval[1][i] = y.floatValue();
        } else {
            retval[1][i] = Float.NaN;
        }
    }
    return retval;
}

From source file:com.sciaps.utils.Util.java

public static void getMinMax(MinMaxObj minMaxObj, XYSeries series, double start, double end) {

    boolean inRange = false;
    for (int i = 0; i < series.getItemCount(); i++) {
        double x = series.getX(i).doubleValue();

        if (x >= start && x <= end) {
            inRange = true;/*from ww w . ja v a 2 s .c  o  m*/
            double y = series.getY(i).doubleValue();
            if (y < minMaxObj.min_) {
                minMaxObj.min_ = y;
            }

            if (y > minMaxObj.max_) {
                minMaxObj.max_ = y;
            }
        } else {
            if (inRange) {
                break;
            }
        }
    }

}

From source file:edu.ucsf.valelab.saim.plot.PlotUtils.java

public static XYSeries normalize(XYSeries input) {
    double max = input.getMaxY();
    // double min = input.getMinY();
    XYSeries output = new XYSeries(input.getKey(), input.getAutoSort(), input.getAllowDuplicateXValues());
    for (int i = 0; i < input.getItemCount(); i++) {
        output.add(input.getX(i), (input.getY(i).doubleValue()) / (max));
    }//from   w w w .  ja va  2s . c o  m
    return output;
}

From source file:com.projity.pm.graphic.chart.ChartModel.java

public static void dumpSeries(XYSeries series) {
    for (int i = 0; i < series.getItemCount(); i++) {
        System.out.println(new java.util.Date(series.getX(i).longValue()) + " " + series.getY(i));
    }/*from  w  ww. ja v  a2 s .com*/
}

From source file:org.gephi.ui.utils.ChartsUtils.java

/**
 * Calculates linear regression points from a XYSeriesCollection data set
 * Code obtained from http://pwnt.be/2009/08/17/simple-linear-regression-with-jfreechart
 *//* w  w  w.  jav a 2  s  . c o  m*/
private static XYDataset regress(XYSeriesCollection data) {
    // Determine bounds
    double xMin = Double.MAX_VALUE, xMax = 0;
    for (int i = 0; i < data.getSeriesCount(); i++) {
        XYSeries ser = data.getSeries(i);
        for (int j = 0; j < ser.getItemCount(); j++) {
            double x = ser.getX(j).doubleValue();
            if (x < xMin) {
                xMin = x;
            }
            if (x > xMax) {
                xMax = x;
            }
        }
    }
    // Create 2-point series for each of the original series
    XYSeriesCollection coll = new XYSeriesCollection();
    for (int i = 0; i < data.getSeriesCount(); i++) {
        XYSeries ser = data.getSeries(i);
        int n = ser.getItemCount();
        double sx = 0, sy = 0, sxx = 0, sxy = 0, syy = 0;
        for (int j = 0; j < n; j++) {
            double x = ser.getX(j).doubleValue();
            double y = ser.getY(j).doubleValue();
            sx += x;
            sy += y;
            sxx += x * x;
            sxy += x * y;
            syy += y * y;
        }
        double b = (n * sxy - sx * sy) / (n * sxx - sx * sx);
        double a = sy / n - b * sx / n;
        XYSeries regr = new XYSeries(ser.getKey());
        regr.add(xMin, a + b * xMin);
        regr.add(xMax, a + b * xMax);
        coll.addSeries(regr);
    }
    return coll;
}

From source file:com.griddynamics.jagger.reporting.chart.ChartHelper.java

public static Pair<String, XYSeriesCollection> adjustTime(XYSeriesCollection chartsCollection,
        Collection<IntervalMarker> markers) {
    int maxTime = 0;
    for (int i = 0; i < chartsCollection.getSeriesCount(); i++) {
        XYSeries series = chartsCollection.getSeries(i);
        for (int j = 0; j < series.getItemCount(); j++) {
            int x = series.getX(j).intValue();
            if (x > maxTime) {
                maxTime = x;/*from   w ww  .  j  a va 2 s.  c  om*/
            }
        }
    }

    String type = "ms";
    int div = 1;

    if (maxTime > 10 * 60 * 1000) {
        div = 60 * 1000;
        type = "min";
    }

    if (maxTime > 30 * 1000) {
        div = 1000;
        type = "sec";
    }

    XYSeriesCollection result = new XYSeriesCollection();

    for (int i = 0; i < chartsCollection.getSeriesCount(); i++) {

        XYSeries old = chartsCollection.getSeries(i);
        XYSeries series = new XYSeries(old.getKey(), old.getAutoSort(), old.getAllowDuplicateXValues());
        for (int j = 0; j < old.getItemCount(); j++) {
            Number x = old.getX(j).doubleValue() / div;
            Number y = old.getY(j);
            series.add(x, y);
        }

        result.addSeries(series);
    }

    if (markers != null) {
        for (IntervalMarker marker : markers) {
            marker.setStartValue(marker.getStartValue() / div);
            marker.setEndValue(marker.getEndValue() / div);
        }
    }

    return Pair.of(type, result);
}

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);
            }// ww w .  j  av a 2  s .c  o  m
        }
    }
    rng[0] = minx;
    rng[1] = miny;
    rng[2] = maxx;
    rng[3] = maxy;
}

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

/**
 * Adds a Gaussian curve to the plot//  ww  w.  java2 s  .co  m
 * 
 * @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);
}