List of usage examples for org.jfree.data.xy XYSeries getKey
public Comparable getKey()
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 *//*ww w . j a v a 2s .c om*/ 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:org.jfree.data.xy.XYSeriesCollection.java
/** * Returns a series from the collection. * * @param key the key (<code>null</code> not permitted). * * @return The series with the specified key. * * @throws UnknownKeyException if <code>key</code> is not found in the * collection./*from w w w.j ava 2 s . c om*/ * * @since 1.0.9 */ public XYSeries getSeries(Comparable key) { ParamChecks.nullNotPermitted(key, "key"); Iterator iterator = this.data.iterator(); while (iterator.hasNext()) { XYSeries series = (XYSeries) iterator.next(); if (key.equals(series.getKey())) { return series; } } throw new UnknownKeyException("Key not found: " + key); }
From source file:org.jfree.data.xy.XYSeriesCollection.java
/** * Returns the index of the series with the specified key, or -1 if no * series has that key./* w w w . j a va2 s . c o m*/ * * @param key the key (<code>null</code> not permitted). * * @return The index. * * @since 1.0.14 */ public int getSeriesIndex(Comparable key) { ParamChecks.nullNotPermitted(key, "key"); int seriesCount = getSeriesCount(); for (int i = 0; i < seriesCount; i++) { XYSeries series = (XYSeries) this.data.get(i); if (key.equals(series.getKey())) { return i; } } return -1; }
From source file:org.jfree.data.xy.XYSeriesCollection.java
/** * Adds a series to the collection and sends a {@link DatasetChangeEvent} * to all registered listeners.//from w w w. jav a 2 s . com * * @param series the series (<code>null</code> not permitted). * * @throws IllegalArgumentException if the key for the series is null or * not unique within the dataset. */ public void addSeries(XYSeries series) { ParamChecks.nullNotPermitted(series, "series"); if (getSeriesIndex(series.getKey()) >= 0) { throw new IllegalArgumentException( "This dataset already contains a series with the key " + series.getKey()); } this.data.add(series); series.addChangeListener(this); series.addVetoableChangeListener(this); fireDatasetChanged(); }
From source file:com.AandR.beans.plotting.LinePlotPanel.LinePlotPanel.java
public void removeSeries(Comparable key) { XYSeries series = plotSeries.getSeries(key); plotSeries.removeSeries(series);//www. ja v a 2 s . c om plotsMap.remove(series.getKey().toString()); }
From source file:org.jfree.data.xy.XYSeriesTest.java
@Test public void testSetKey() { XYSeries s1 = new XYSeries("S"); s1.setKey("S1"); assertEquals("S1", s1.getKey()); XYSeriesCollection c = new XYSeriesCollection(); c.addSeries(s1);/* ww w . j av a 2 s . c o m*/ XYSeries s2 = new XYSeries("S2"); c.addSeries(s2); // now we should be allowed to change s1's key to anything but "S2" s1.setKey("OK"); assertEquals("OK", s1.getKey()); try { s1.setKey("S2"); fail("Expect an exception here."); } catch (IllegalArgumentException e) { // OK } // after s1 is removed from the collection, we should be able to set // the key to anything we want... c.removeSeries(s1); s1.setKey("S2"); // check that removing by index also works s1.setKey("S1"); c.addSeries(s1); c.removeSeries(1); s1.setKey("S2"); }
From source file:org.jfree.data.xy.junit.XYSeriesCollectionTest.java
/** * Test that a series belonging to a collection can be renamed (in fact, * because of a bug this was not possible in JFreeChart 1.0.14). *///from www . j a v a 2 s . c o m public void testSeriesRename() { // first check that a valid renaming works XYSeries series1 = new XYSeries("A"); XYSeries series2 = new XYSeries("B"); XYSeriesCollection collection = new XYSeriesCollection(); collection.addSeries(series1); collection.addSeries(series2); series1.setKey("C"); assertEquals("C", collection.getSeries(0).getKey()); // next, check that setting a duplicate key fails try { series2.setKey("C"); } catch (IllegalArgumentException e) { // expected } assertEquals("B", series2.getKey()); // the series name should not // change because "C" is already the key for the other series in the // collection }
From source file:org.pentaho.plugin.jfreereport.reportcharts.XYChartExpression.java
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); }//w w w . ja v a 2 s . com } return tableXYDataset; }
From source file:org.jfree.data.xy.XYSeriesCollectionTest.java
/** * Test that a series belonging to a collection can be renamed (in fact, * because of a bug this was not possible in JFreeChart 1.0.14). *//*w w w .ja v a 2 s .com*/ @Test public void testSeriesRename() { // first check that a valid renaming works XYSeries series1 = new XYSeries("A"); XYSeries series2 = new XYSeries("B"); XYSeriesCollection collection = new XYSeriesCollection(); collection.addSeries(series1); collection.addSeries(series2); series1.setKey("C"); assertEquals("C", collection.getSeries(0).getKey()); // next, check that setting a duplicate key fails try { series2.setKey("C"); fail("Expected an IllegalArgumentException."); } catch (IllegalArgumentException e) { // expected } assertEquals("B", series2.getKey()); // the series name should not // change because "C" is already the key for the other series in the // collection }
From source file:org.esa.snap.rcp.statistics.ScatterPlotPanel.java
private XYIntervalSeries computeAcceptableDeviationData(double lowerBound, double upperBound) { final XYSeries identity = DatasetUtilities.sampleFunction2DToSeries(x -> x, lowerBound, upperBound, 100, "1:1 line"); final XYIntervalSeries xyIntervalSeries = new XYIntervalSeries(identity.getKey()); for (int i = 0; i < identity.getItemCount(); i++) { XYDataItem item = identity.getDataItem(i); final double x = item.getXValue(); final double y = item.getYValue(); if (scatterPlotModel.showAcceptableDeviation) { final double acceptableDeviation = scatterPlotModel.acceptableDeviationInterval; final double xOff = acceptableDeviation * x / 100; final double yOff = acceptableDeviation * y / 100; xyIntervalSeries.add(x, x - xOff, x + xOff, y, y - yOff, y + yOff); } else {//from ww w . j a v a 2 s . c om xyIntervalSeries.add(x, x, x, y, y, y); } } return xyIntervalSeries; }