List of usage examples for org.jfree.data.xy XYDataItem getX
public Number getX()
From source file:statistic.graph.gui.Charts.java
private static void initXAxis(XYPlot plot, XYDataset dataset) { plot.setDomainAxis(new NumberAxis(plot.getDomainAxis().getLabel())); XYSeriesCollection collection = (XYSeriesCollection) dataset; double max = Double.NEGATIVE_INFINITY; double min = Double.POSITIVE_INFINITY; if (collection != null) { for (int s = 0; s < collection.getSeriesCount(); s++) { for (int d = 0; d < collection.getItemCount(s); d++) { XYDataItem data = collection.getSeries(s).getDataItem(d); if (data.getX().longValue() == Integer.MAX_VALUE || data.getX().longValue() == Integer.MIN_VALUE) { continue; }/*from ww w . ja v a 2 s.c om*/ if (data.getX().doubleValue() > max) { max = data.getX().doubleValue(); } if (data.getX().doubleValue() < min) { min = data.getX().doubleValue(); } } } if (min < max) { plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.getDomainAxis().setRange(min - 0.5, max + 0.5); for (int s = 0; s < collection.getSeriesCount(); s++) { XYSeries series = collection.getSeries(s); if (series.indexOf(Integer.MIN_VALUE) >= 0) { XYDataItem item = series.remove((Number) Integer.MIN_VALUE); if (series.indexOf(min) < 0) { series.add(min, item.getY()); } } if (series.indexOf(Integer.MAX_VALUE) >= 0) { XYDataItem item = series.remove((Number) Integer.MAX_VALUE); if (series.indexOf(max) < 0) { series.add(max, item.getY()); } } } } else { plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.getDomainAxis().setRange(0 - 0.5, 1 + 0.5); } } else { plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.getDomainAxis().setRange(0 - 0.5, 1 + 0.5); } }
From source file:org.fhcrc.cpl.viewer.mrm.Utils.java
public static double getWeightedAverageDaughtersTime(XYSeriesCollection daughterSet) { double retVal = 0.0; double yTot = 0.0; double xWeight = 0.0; for (Object xyso : daughterSet.getSeries()) { XYSeries xys = (XYSeries) xyso;/*from w w w . j ava 2 s . co m*/ for (Object xydio : xys.getItems()) { XYDataItem xydi = (XYDataItem) xydio; xWeight += (xydi.getX().doubleValue() * xydi.getY().doubleValue()); yTot += xydi.getY().doubleValue(); } } if (yTot > 0) retVal = xWeight / yTot; return retVal; }
From source file:com.googlecode.psiprobe.beans.stats.providers.AbstractSeriesProvider.java
protected XYSeries toSeries(String legend, List stats) { XYSeries xySeries = new XYSeries(legend, true, false); synchronized (stats) { for (int i = 0; i < stats.size(); i++) { XYDataItem item = (XYDataItem) stats.get(i); xySeries.addOrUpdate(item.getX(), item.getY()); }// w w w . j ava 2 s . co m } return xySeries; }
From source file:statistic.graph.XYChart.java
private void initXAxis(String label) { plot.setDomainAxis(new NumberAxis(label)); double max = Double.NEGATIVE_INFINITY; double min = Double.POSITIVE_INFINITY; for (int s = 0; s < collection.getSeriesCount(); s++) { for (int d = 0; d < collection.getItemCount(s); d++) { XYDataItem data = collection.getSeries(s).getDataItem(d); if (data.getX().longValue() == Integer.MAX_VALUE || data.getX().longValue() == Integer.MIN_VALUE) { continue; }/* w ww . ja v a 2 s .co m*/ if (data.getX().doubleValue() > max) { max = data.getX().doubleValue(); } if (data.getX().doubleValue() < min) { min = data.getX().doubleValue(); } } } plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.getDomainAxis().setRange(min - 0.5, max + 0.5); }
From source file:com.github.dougkelly88.FLIMPlateReaderGUI.FLIMClasses.Classes.FindMaxpoint.java
public void acqMaxpointData() { ArrayList<Integer> signal = new ArrayList<Integer>(); ArrayList<Integer> delays = new ArrayList<Integer>(); // instrument interacting fn, currently dummy // REMEMBER TO APPLY THRESHOLD // plot maxpoint data findMaxpointData_ = createDummyMaxpointData(0); XYPlot plot = chart_.getXYPlot();// ww w . ja va2s.c o m plot.setDataset(0, findMaxpointData_); // assign maxpoint - easier when this is real data... ArrayList<XYDataItem> dummy = new ArrayList<XYDataItem>( ((XYSeriesCollection) findMaxpointData_).getSeries(0).getItems()); for (XYDataItem dummy1 : dummy) { delays.add((Integer) dummy1.getX().intValue()); signal.add((Integer) dummy1.getY().intValue()); } int[] res = findMaxIndex(signal); maxpointDelay_ = delays.get(res[0]); // estimate lifetime signal = new ArrayList<Integer>(signal.subList(res[0], signal.size())); delays = new ArrayList<Integer>(delays.subList(res[0], delays.size())); double sumt2 = 0; double sumt = 0; double sumtlnI = 0; double sumlnI = 0; for (int i = 0; i < signal.size(); i++) { sumt2 = sumt2 + delays.get(i) * delays.get(i); sumt = sumt + delays.get(i); sumlnI = (sumlnI + log((double) signal.get(i))); sumtlnI = sumtlnI + log((double) signal.get(i)) * delays.get(i); } lifetime_ = -(delays.size() * sumt2 - sumt * sumt) / (delays.size() * sumtlnI - sumt * sumlnI); }
From source file:sim.portrayal.inspector.TimeSeriesChartingPropertyInspector.java
protected void updateSeries(double time, double lastTime) { double d = 0; GlobalAttributes globalAttributes = getGlobalAttributes(); // FIRST, load the aggregate series with the items aggregateSeries.add(time, d = valueFor(properties.getValue(index)), false); int len = aggregateSeries.getItemCount(); // SECOND, determine if it's time to dump stuff into the main series long interval = globalAttributes.interval; double intervalMark = time % interval; if (!/*from ww w . j a va2s . co m*/ // I think these are the three cases for when we may need to update because // we've exceeded the next interval (intervalMark == 0 || (time - lastTime >= interval) || lastTime % interval > intervalMark)) return; // not yet // THIRD determine how and when to dump stuff into the main series double y = 0; // make compiler happy double temp; switch (globalAttributes.aggregationMethod) { case AGGREGATIONMETHOD_CURRENT: // in this case the aggregateSeries is sort of worthless addToMainSeries(time, d, false); break; case AGGREGATIONMETHOD_MAX: double maxX = 0; for (int i = 0; i < len; i++) { XYDataItem item = (XYDataItem) (aggregateSeries.getDataItem(i)); y = item.getY().doubleValue(); temp = item.getX().doubleValue(); if (maxX < temp || i == 0) maxX = temp; } addToMainSeries(maxX, y, false); break; case AGGREGATIONMETHOD_MIN: double minX = 0; for (int i = 0; i < len; i++) { XYDataItem item = (XYDataItem) (aggregateSeries.getDataItem(i)); y = item.getY().doubleValue(); temp = item.getX().doubleValue(); if (minX > temp || i == 0) minX = temp; } addToMainSeries(minX, y, false); break; case AGGREGATIONMETHOD_MEAN: double sumX = 0; int n = 0; for (int i = 0; i < len; i++) { XYDataItem item = (XYDataItem) (aggregateSeries.getDataItem(i)); y = item.getY().doubleValue(); sumX += item.getX().doubleValue(); n++; } if (n == 0) { // no element -- do nothing } else addToMainSeries(sumX / n, y, false); break; default: throw new RuntimeException("No valid aggregation method provided"); } aggregateSeries.clear(); }
From source file:org.jfree.data.xy.XYDataItem.java
/** * Returns an integer indicating the order of this object relative to * another object.//from w ww .j av a 2 s .c om * <P> * For the order we consider only the x-value: * negative == "less-than", zero == "equal", positive == "greater-than". * * @param o1 the object being compared to. * * @return An integer indicating the order of this data pair object * relative to another object. */ @Override public int compareTo(Object o1) { int result; // CASE 1 : Comparing to another TimeSeriesDataPair object // ------------------------------------------------------- if (o1 instanceof XYDataItem) { XYDataItem dataItem = (XYDataItem) o1; double compare = this.x.doubleValue() - dataItem.getX().doubleValue(); if (compare > 0.0) { result = 1; } else { if (compare < 0.0) { result = -1; } else { result = 0; } } } // CASE 2 : Comparing to a general object // --------------------------------------------- else { // consider time periods to be ordered after general objects result = 1; } return result; }
From source file:com.googlecode.psiprobe.model.stats.StatsCollection.java
private Map deserialize(File f) { Map stats = null;/*w ww . j av a 2s . c om*/ if (f.exists() && f.canRead()) { long t = System.currentTimeMillis(); try { FileInputStream fis = new FileInputStream(f); try { stats = (Map) (new XStream().fromXML(fis)); if (stats != null) { // adjust stats data so that charts look realistic. // we do that by ending the previous stats group with 0 value // and starting the current stats group also with 0 // thus giving the chart nice plunge to zero indicating downtime // // and lets not bother about rotating stats; // regular stats collection cycle will do it for (Iterator it = stats.keySet().iterator(); it.hasNext();) { List l = (List) stats.get(it.next()); if (l.size() > 0) { XYDataItem xy = (XYDataItem) l.get(l.size() - 1); l.add(new XYDataItem(xy.getX().longValue() + 1, 0)); l.add(new XYDataItem(System.currentTimeMillis(), 0)); } } } } finally { fis.close(); } logger.debug("stats data read in " + (System.currentTimeMillis() - t) + "ms."); } catch (Throwable e) { logger.error("Could not read stats data from " + f.getAbsolutePath(), e); // // make sure we always re-throw ThreadDeath // if (e instanceof ThreadDeath) { throw (ThreadDeath) e; } } } return stats; }
From source file:psiprobe.model.stats.StatsCollection.java
/** * Deserialize./*w ww .jav a2s. co m*/ * * @param file the file * @return the map */ private Map<String, List<XYDataItem>> deserialize(File file) { Map<String, List<XYDataItem>> stats = null; if (file.exists() && file.canRead()) { long start = System.currentTimeMillis(); try { try (FileInputStream fis = new FileInputStream(file)) { stats = (Map<String, List<XYDataItem>>) (new XStream().fromXML(fis)); if (stats != null) { // adjust stats data so that charts look realistic. // we do that by ending the previous stats group with 0 value // and starting the current stats group also with 0 // thus giving the chart nice plunge to zero indicating downtime // and lets not bother about rotating stats; // regular stats collection cycle will do it for (String key : stats.keySet()) { List<XYDataItem> list = stats.get(key); if (!list.isEmpty()) { XYDataItem xy = list.get(list.size() - 1); list.add(new XYDataItem(xy.getX().longValue() + 1, 0)); list.add(new XYDataItem(System.currentTimeMillis(), 0)); } } } } logger.debug("stats data read in {}ms", (System.currentTimeMillis() - start)); } catch (Exception e) { logger.error("Could not read stats data from '{}'", file.getAbsolutePath(), e); } } return stats; }
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 ww .j a va2s.c o m*/ 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; }