Java Code Examples for org.jfree.data.xy.XYSeries#getDataItem()

The following examples show how to use org.jfree.data.xy.XYSeries#getDataItem() . 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: 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 3
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 4
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 5
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();
}