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

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

Introduction

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

Prototype

public int indexOf(Number x) 

Source Link

Document

Returns the index of the item with the specified x-value, or a negative index if the series does not contain an item with that x-value.

Usage

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;
                }//  ww w . ja  va  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.jfree.data.xy.DefaultTableXYDataset.java

/**
 * Returns <code>true</code> if all the y-values for the specified x-value
 * are <code>null</code> and <code>false</code> otherwise.
 *
 * @param x  the x-value.//from   w w  w .  j a v a2s.  c  o  m
 *
 * @return A boolean.
 */
protected boolean canPrune(Number x) {
    for (int s = 0; s < this.data.size(); s++) {
        XYSeries series = (XYSeries) this.data.get(s);
        if (series.getY(series.indexOf(x)) != null) {
            return false;
        }
    }
    return true;
}

From source file:org.jfree.data.xy.XYSeriesTest.java

/**
 * A check for the indexOf(Number) method when the series has duplicate
 * x-values./*w ww  . j  a v a2s  .co  m*/
 */
@Test
public void testIndexOf3() {
    XYSeries s1 = new XYSeries("Series 1");
    s1.add(1.0, 1.0);
    s1.add(2.0, 2.0);
    s1.add(2.0, 3.0);
    assertEquals(0, s1.indexOf(new Double(1.0)));
    assertEquals(1, s1.indexOf(new Double(2.0)));
}

From source file:org.jfree.data.xy.XYSeriesTest.java

/**
 * Simple test for the indexOf() method.
 *//*from  ww  w  .j av  a  2  s .  c o m*/
@Test
public void testIndexOf() {
    XYSeries s1 = new XYSeries("Series 1");
    s1.add(1.0, 1.0);
    s1.add(2.0, 2.0);
    s1.add(3.0, 3.0);
    assertEquals(0, s1.indexOf(new Double(1.0)));
    assertEquals(1, s1.indexOf(new Double(2.0)));
    assertEquals(2, s1.indexOf(new Double(3.0)));
    assertEquals(-4, s1.indexOf(new Double(99.9)));
}

From source file:org.jfree.data.xy.XYSeriesTest.java

/**
 * A check for the indexOf() method for an unsorted series.
 *//*from ww w  .  j  a  v  a2 s  .co m*/
@Test
public void testIndexOf2() {
    XYSeries s1 = new XYSeries("Series 1", false, true);
    s1.add(1.0, 1.0);
    s1.add(3.0, 3.0);
    s1.add(2.0, 2.0);
    assertEquals(0, s1.indexOf(new Double(1.0)));
    assertEquals(1, s1.indexOf(new Double(3.0)));
    assertEquals(2, s1.indexOf(new Double(2.0)));
}