org.jfree.data.xy.XYDataItem Java Examples

The following examples show how to use org.jfree.data.xy.XYDataItem. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScatterPlotPanel.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
private XYIntervalSeries computeRegressionData(double xStart, double xEnd) {
    if (scatterpointsDataset.getItemCount(0) > 1) {
        final double[] coefficients = Regression.getOLSRegression(scatterpointsDataset, 0);
        final Function2D curve = new LineFunction2D(coefficients[0], coefficients[1]);
        final XYSeries regressionData = DatasetUtilities.sampleFunction2DToSeries(curve, xStart, xEnd, 100, "regression line");
        final XYIntervalSeries xyIntervalRegression = new XYIntervalSeries(regressionData.getKey());
        for (int i = 0; i < regressionData.getItemCount(); i++) {
            XYDataItem item = regressionData.getDataItem(i);
            final double x = item.getXValue();
            final double y = item.getYValue();
            xyIntervalRegression.add(x, x, x, y, y, y);
        }
        return xyIntervalRegression;
    } else {
        Dialogs.showInformation("Unable to compute regression line.\n" +
                                        "At least 2 values are needed to compute regression coefficients.");
        return null;
    }
}
 
Example #2
Source File: XYSeriesTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the addOrUpdate() method.
 */
public void testAddOrUpdate() {
    XYSeries series = new XYSeries("S1", true, false);
    XYDataItem old = series.addOrUpdate(new Long(1), new Long(2));
    assertTrue(old == null);
    assertEquals(1, series.getItemCount());
    assertEquals(new Long(2), series.getY(0));

    old = series.addOrUpdate(new Long(2), new Long(3));
    assertTrue(old == null);
    assertEquals(2, series.getItemCount());
    assertEquals(new Long(3), series.getY(1));

    old = series.addOrUpdate(new Long(1), new Long(99));
    assertEquals(new XYDataItem(new Long(1), new Long(2)), old);
    assertEquals(2, series.getItemCount());
    assertEquals(new Long(99), series.getY(0));
    assertEquals(new Long(3), series.getY(1));
}
 
Example #3
Source File: XYSeriesTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the addOrUpdate() method.
 */
public void testAddOrUpdate() {
    XYSeries series = new XYSeries("S1");
    XYDataItem old = series.addOrUpdate(new Long(1), new Long(2));
    assertTrue(old == null);
    assertEquals(1, series.getItemCount());
    assertEquals(new Long(2), series.getY(0));
    
    old = series.addOrUpdate(new Long(2), new Long(3));
    assertTrue(old == null);
    assertEquals(2, series.getItemCount());
    assertEquals(new Long(3), series.getY(1));

    old = series.addOrUpdate(new Long(1), new Long(99));
    assertEquals(new XYDataItem(new Long(1), new Long(2)), old);
    assertEquals(2, series.getItemCount());
    assertEquals(new Long(99), series.getY(0));
    assertEquals(new Long(3), series.getY(1));
}
 
Example #4
Source File: PseudoSpectrumDataSet.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
public void addDP(int series, double x, double y, String ann) {
  if (series >= getSeriesCount())
    throw new OutOfRangeException(series, 0, getSeriesCount());

  XYDataItem dp = new XYDataItem(x, y);
  getSeries(series).add(dp);
  if (ann != null) {
    addAnnotation(dp, ann);
  }
}
 
Example #5
Source File: PseudoSpectrumDataSet.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
public String getAnnotation(int series, int item) {
  if (annotation == null)
    return null;
  XYDataItem itemDataPoint = getSeries(series).getDataItem(item);
  for (XYDataItem key : annotation.keySet()) {
    if (Math.abs(key.getXValue() - itemDataPoint.getXValue()) < 0.0001)
      return annotation.get(key);
  }
  return null;
}
 
Example #6
Source File: PseudoSpectrumDataSet.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
private void addDPIdentity(MZTolerance mzTolerance, AbstractMSMSDataPointIdentity ann) {
  for (int s = 0; s < getSeriesCount(); s++) {
    XYSeries series = getSeries(s);
    for (int i = 0; i < series.getItemCount(); i++) {
      XYDataItem dp = series.getDataItem(i);
      if (mzTolerance.checkWithinTolerance(dp.getXValue(), ann.getMZ())) {
        addAnnotation(dp, ann.getName());
      }
    }
  }
}
 
Example #7
Source File: PIDGraph.java    From BowlerStudio with GNU General Public License v3.0 5 votes vote down vote up
public void run(){
	while (true){
		ThreadUtil.wait(50);
		if(lastData[0] != data[0] || lastData[1]!=data[1]){
			lastData[0]=data[0];
			lastData[1]=data[1];
			try{
				
				
				double time = (System.currentTimeMillis()-startTime);
				
				dataTable.add(new GraphDataElement((long) time,data));
				XYDataItem s = new XYDataItem(time,data[0]);
				XYDataItem p = new XYDataItem(time,data[1]);

				if(setpoints.getItemCount()>99){
					setpoints.remove(0);
				}
				setpoints.add(s);
				
				if(positions.getItemCount()>99){
					positions.remove(0);
				}
				positions.add(p);

			}catch(Exception e){
				System.err.println("Failed to set a data point");
				e.printStackTrace();
				Log.error(e);
				Log.error(e.getStackTrace());
				init();
			}
		}
	}
}
 
Example #8
Source File: XYChartExpression.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected TableXYDataset convertToTable( final XYSeriesCollection xyDataset ) {
  final ExtCategoryTableXYDataset tableXYDataset = new ExtCategoryTableXYDataset();
  final int count = xyDataset.getSeriesCount();
  for ( int i = 0; i < count; i++ ) {
    final XYSeries timeSeries = xyDataset.getSeries( i );
    final Comparable key = timeSeries.getKey();
    final int itemCount = timeSeries.getItemCount();
    for ( int ic = 0; ic < itemCount; ic++ ) {
      final XYDataItem seriesDataItem = timeSeries.getDataItem( ic );
      tableXYDataset.add( seriesDataItem.getX(), seriesDataItem.getY(), key, false );
    }
  }
  return tableXYDataset;
}
 
Example #9
Source File: CurveGraphPanel.java    From EccPlayground with Apache License 2.0 5 votes vote down vote up
public void showAnnotations() {
    XYItemRenderer renderer = getChart().getXYPlot().getRenderer();
    renderer.removeAnnotations();

    for (int i = 0; i < eccSeries.getItemCount(); i++) {
        XYDataItem item = (XYDataItem) eccSeries.getDataItem(i);
        XYTextAnnotation annon = new XYTextAnnotation(new Integer(i).toString(), item.getX().longValue(), item
                .getY().longValue());
        renderer.addAnnotation(annon);
    }
}
 
Example #10
Source File: PseudoSpectrumDataSet.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
public void addDP(int series, double x, double y, String ann) {
  if (series >= getSeriesCount())
    throw new OutOfRangeException(series, 0, getSeriesCount());

  XYDataItem dp = new XYDataItem(x, y);
  getSeries(series).add(dp);
  if (ann != null) {
    addAnnotation(dp, ann);
  }
}
 
Example #11
Source File: PseudoSpectrumDataSet.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
public String getAnnotation(int series, int item) {
  if (annotation == null)
    return null;
  XYDataItem itemDataPoint = getSeries(series).getDataItem(item);
  for (XYDataItem key : annotation.keySet()) {
    if (Math.abs(key.getXValue() - itemDataPoint.getXValue()) < 0.0001)
      return annotation.get(key);
  }
  return null;
}
 
Example #12
Source File: PseudoSpectrumDataSet.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
private void addDPIdentity(MZTolerance mzTolerance, AbstractMSMSDataPointIdentity ann) {
  for (int s = 0; s < getSeriesCount(); s++) {
    XYSeries series = getSeries(s);
    for (int i = 0; i < series.getItemCount(); i++) {
      XYDataItem dp = series.getDataItem(i);
      if (mzTolerance.checkWithinTolerance(dp.getXValue(), ann.getMZ())) {
        addAnnotation(dp, ann.getName());
      }
    }
  }
}
 
Example #13
Source File: XYDataItemTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Confirm that the equals method can distinguish all the required fields.
 */
public void testEquals() {

    XYDataItem i1 = new XYDataItem(1.0, 1.1);
    XYDataItem i2 = new XYDataItem(1.0, 1.1);
    assertTrue(i1.equals(i2));
    assertTrue(i2.equals(i1));

    i1.setY(new Double(9.9));
    assertFalse(i1.equals(i2));

    i2.setY(new Double(9.9));
    assertTrue(i1.equals(i2));

}
 
Example #14
Source File: XYDataItemTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Confirm that the equals method can distinguish all the required fields.
 */
public void testEquals() {
    
    XYDataItem i1 = new XYDataItem(1.0, 1.1);
    XYDataItem i2 = new XYDataItem(1.0, 1.1);
    assertTrue(i1.equals(i2));
    assertTrue(i2.equals(i1));

    i1.setY(new Double(9.9));
    assertFalse(i1.equals(i2));

    i2.setY(new Double(9.9));
    assertTrue(i1.equals(i2));

}
 
Example #15
Source File: Volcanoplot.java    From chipster with MIT License 4 votes vote down vote up
protected void updateXYSerieses() throws MicroarrayException {

		Iterator<Float> xValues = getXValueIterator();
		Iterator<Float> yValues = getYValueIterator();

		XYSeries greenSeries = new XYSeries("");
		XYSeries blackSeries = new XYSeries("");
		XYSeries redSeries = new XYSeries("");
		XYSeries selectedSeries = new XYSeries("");

		int row = 0;
		while (xValues.hasNext() && yValues.hasNext()) {

			float x = xValues.next();
			float y = yValues.next();

			boolean overYThreshold = y >= -Math.log10(0.05);
			boolean overXThreshold = Math.abs(x) >= 1f;

			if (selectedIndexes.contains(row)) {
				selectedSeries.add(new XYDataItem(x, y));
			} else {

				if (overYThreshold && overXThreshold) {
					if (x < 0) {
						greenSeries.add(new XYDataItem(x, y));

					} else {
						redSeries.add(new XYDataItem(x, y));

					}
				} else {
					blackSeries.add(new XYDataItem(x, y));

				}
			}
			row++;
		}

		XYSeriesCollection dataset = new XYSeriesCollection();
		dataset.addSeries(greenSeries);
		dataset.addSeries(redSeries);
		dataset.addSeries(blackSeries);
		dataset.addSeries(selectedSeries);

		plot.setDataset(dataset);

	}
 
Example #16
Source File: FunctionXYSeries.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
public void updateByIndex(int index, Number x, Number y) {
   XYDataItem newNode = new XYDataItem(x, y);
   data.remove(index);
   data.add(index, newNode);
   fireSeriesChanged();
}
 
Example #17
Source File: GraphData.java    From iBioSim with Apache License 2.0 4 votes vote down vote up
public void exportDataFile(File file, int output) throws Exception {
	int count = curData.getSeries(0).getItemCount();
	for (int i = 1; i < curData.getSeriesCount(); i++) {
		if (curData.getSeries(i).getItemCount() != count) {				
			throw new Exception("Data series do not have the same number of points!");
		}
	}
	for (int j = 0; j < count; j++) {
		Number Xval = curData.getSeries(0).getDataItem(j).getX();
		for (int i = 1; i < curData.getSeriesCount(); i++) {
			if (!curData.getSeries(i).getDataItem(j).getX().equals(Xval)) {
				throw new Exception("Data series time points are not the same!");
			}
		}
	}
	FileOutputStream csvFile = new FileOutputStream(file);
	PrintWriter csvWriter = new PrintWriter(csvFile);
	if (output == 7) {
		csvWriter.print("((");
	}
	else if (output == 6) {
		csvWriter.print("#");
	}
	csvWriter.print("\"Time\"");
	count = curData.getSeries(0).getItemCount();
	int pos = 0;
	for (int i = 0; i < curData.getSeriesCount(); i++) {
		if (output == 6) {
			csvWriter.print(" ");
		}
		else {
			csvWriter.print(",");
		}
		csvWriter.print("\"" + curData.getSeriesKey(i) + "\"");
		if (curData.getSeries(i).getItemCount() > count) {
			count = curData.getSeries(i).getItemCount();
			pos = i;
		}
	}
	if (output == 7) {
		csvWriter.print(")");
	}
	else {
		csvWriter.println("");
	}
	for (int j = 0; j < count; j++) {
		if (output == 7) {
			csvWriter.print(",");
		}
		for (int i = 0; i < curData.getSeriesCount(); i++) {
			if (i == 0) {
				if (output == 7) {
					csvWriter.print("(");
				}
				csvWriter.print(curData.getSeries(pos).getDataItem(j).getX());
			}
			XYSeries data = curData.getSeries(i);
			if (j < data.getItemCount()) {
				XYDataItem item = data.getDataItem(j);
				if (output == 6) {
					csvWriter.print(" ");
				}
				else {
					csvWriter.print(",");
				}
				csvWriter.print(item.getY());
			}
			else {
				if (output == 6) {
					csvWriter.print(" ");
				}
				else {
					csvWriter.print(",");
				}
			}
		}
		if (output == 7) {
			csvWriter.print(")");
		}
		else {
			csvWriter.println("");
		}
	}
	if (output == 7) {
		csvWriter.println(")");
	}
	csvWriter.close();
	csvFile.close();
}
 
Example #18
Source File: PseudoSpectrumDataSet.java    From mzmine2 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Add annotation
 * 
 * @param dp
 * @param ann
 */
public void addAnnotation(XYDataItem dp, String ann) {
  if (annotation == null)
    this.annotation = new HashMap<>();
  annotation.put(dp, ann);
}
 
Example #19
Source File: AgentDataset.java    From jamel with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Returns the specified {@code XYDataItem} for the specified period.
 * 
 * @param x
 *            the key for the x value.
 * @param y
 *            the key for the y value.
 * @param t
 *            the period.
 * @return the specified {@code XYDataItem}.
 */
XYDataItem getXYDataItem(String x, String y, int t);
 
Example #20
Source File: PseudoSpectrumDataSet.java    From mzmine3 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Add annotation
 * 
 * @param dp
 * @param ann
 */
public void addAnnotation(XYDataItem dp, String ann) {
  if (annotation == null)
    this.annotation = new HashMap<>();
  annotation.put(dp, ann);
}