Example usage for org.jfree.data.xy XYDataItem setY

List of usage examples for org.jfree.data.xy XYDataItem setY

Introduction

In this page you can find the example usage for org.jfree.data.xy XYDataItem setY.

Prototype

public void setY(Number y) 

Source Link

Document

Sets the y-value for this data item.

Usage

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

/**
 * Confirm that the equals method can distinguish all the required fields.
 *//*from w ww. j ava  2  s  .co m*/
@Test
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));
}

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

/**
 * Updates the value of an item in the series and sends a
 * {@link SeriesChangeEvent} to all registered listeners.
 *
 * @param index  the item (zero based index).
 * @param y  the new value (<code>null</code> permitted).
 *
 * @since 1.0.1// www  .  ja va  2  s .c o  m
 */
public void updateByIndex(int index, Number y) {
    XYDataItem item = getDataItem(index);
    item.setY(y);
    fireSeriesChanged();
}

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

/**
 * Updates an item in the series.//from w ww. ja va  2s  .  com
 *
 * @param x  the x-value (<code>null</code> not permitted).
 * @param y  the y-value (<code>null</code> permitted).
 *
 * @throws SeriesException if there is no existing item with the specified
 *         x-value.
 */
public void update(Number x, Number y) {
    int index = indexOf(x);
    if (index < 0) {
        throw new SeriesException("No observation for x = " + x);
    } else {
        XYDataItem item = getDataItem(index);
        item.setY(y);
        fireSeriesChanged();
    }
}

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

/**
 * Updates the value of an item in the series and sends a
 * {@link SeriesChangeEvent} to all registered listeners.
 *
 * @param index  the item (zero based index).
 * @param y  the new value (<code>null</code> permitted).
 *
 * @since 1.0.1/*from  ww w . j a  va 2s  .co m*/
 */
public void updateByIndex(int index, Number y) {
    XYDataItem item = getDataItem(index);

    item.setY(y);
    fireSeriesChanged();
}

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

/**
 * Updates an item in the series.//from   ww  w.j a v a 2s . c  o m
 *
 * @param x  the x-value (<code>null</code> not permitted).
 * @param y  the y-value (<code>null</code> permitted).
 *
 * @throws SeriesException if there is no existing item with the
 *         specified x-value.
 */
public void update(Number x, Number y) {
    int index = indexOf(x);

    if (index < 0) {
        throw new SeriesException("No observation for x = " + x);
    } else {
        XYDataItem item = getDataItem(index);
        item.setY(y);
        fireSeriesChanged();
    }
}

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

/**
 * Adds or updates an item in the series and sends a
 * {@link SeriesChangeEvent} to all registered listeners.
 *
 * @param x  the x-value (<code>null</code> not permitted).
 * @param y  the y-value (<code>null</code> permitted).
 *
 * @return A copy of the overwritten data item, or <code>null</code> if no
 *         item was overwritten./*from w ww.j  ava2  s  . c o m*/
 */
public XYDataItem addOrUpdate(Number x, Number y) {
    if (x == null) {
        throw new IllegalArgumentException("Null 'x' argument.");
    }

    // if we get to here, we know that duplicate X values are not permitted
    XYDataItem overwritten = null;
    int index = indexOf(x);
    if (index >= 0 && !this.allowDuplicateXValues) {
        XYDataItem existing = (XYDataItem) this.data.get(index);
        try {
            overwritten = (XYDataItem) existing.clone();
        } catch (CloneNotSupportedException e) {
            throw new SeriesException("Couldn't clone XYDataItem!");
        }
        existing.setY(y);
    } else {
        // if the series is sorted, the negative index is a result from
        // Collections.binarySearch() and tells us where to insert the
        // new item...otherwise it will be just -1 and we should just
        // append the value to the list...
        if (this.autoSort) {
            this.data.add(-index - 1, new XYDataItem(x, y));
        } else {
            this.data.add(new XYDataItem(x, y));
        }
        // check if this addition will exceed the maximum item count...
        if (getItemCount() > this.maximumItemCount) {
            this.data.remove(0);
        }
    }
    fireSeriesChanged();
    return overwritten;
}

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

/**
 * Adds or updates an item in the series and sends a
 * {@link SeriesChangeEvent} to all registered listeners.
 *
 * @param x  the x-value (<code>null</code> not permitted).
 * @param y  the y-value (<code>null</code> permitted).
 *
 * @return A copy of the overwritten data item, or <code>null</code> if no
 *         item was overwritten./* w  ww.ja v  a2  s  . c  o  m*/
 */
public XYDataItem addOrUpdate(Number x, Number y) {
    if (x == null) {
        throw new IllegalArgumentException("Null 'x' argument.");
    }
    if (this.allowDuplicateXValues) {
        add(x, y);
        return null;
    }

    // if we get to here, we know that duplicate X values are not permitted
    XYDataItem overwritten = null;
    int index = indexOf(x);
    if (index >= 0) {
        XYDataItem existing = (XYDataItem) this.data.get(index);
        try {
            overwritten = (XYDataItem) existing.clone();
        } catch (CloneNotSupportedException e) {
            throw new SeriesException("Couldn't clone XYDataItem!");
        }
        existing.setY(y);
    } else {
        // if the series is sorted, the negative index is a result from
        // Collections.binarySearch() and tells us where to insert the
        // new item...otherwise it will be just -1 and we should just
        // append the value to the list...
        if (this.autoSort) {
            this.data.add(-index - 1, new XYDataItem(x, y));
        } else {
            this.data.add(new XYDataItem(x, y));
        }
        // check if this addition will exceed the maximum item count...
        if (getItemCount() > this.maximumItemCount) {
            this.data.remove(0);
        }
    }
    fireSeriesChanged();
    return overwritten;
}

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

/**
 * Adds or updates an item in the series and sends a
 * {@link SeriesChangeEvent} to all registered listeners.
 *
 * @param x  the x-value (<code>null</code> not permitted).
 * @param y  the y-value (<code>null</code> permitted).
 *
 * @return A copy of the overwritten data item, or
 *         <code>null</code> if noitem was overwritten.
 *///from  w w w  . j a  v  a 2 s.c o  m
public XYDataItem addOrUpdate(Number x, Number y) {
    if (x == null) {
        throw new IllegalArgumentException("Null 'x' argument.");
    }

    // if we get to here, we know that duplicate X values are not permitted
    XYDataItem overwritten = null;
    int index = indexOf(x);
    if (index >= 0 && !this.allowDuplicateXValues) {
        XYDataItem existing = (XYDataItem) this.data.get(index);
        try {
            overwritten = (XYDataItem) existing.clone();
        } catch (CloneNotSupportedException e) {
            throw new SeriesException("Couldn't clone XYDataItem!");
        }
        existing.setY(y);
    } else {

        // if the series is sorted, the negative index is a result from
        // Collections.binarySearch() and tells us where to insert the
        // new item...otherwise it will be just -1 and we should just
        // append the value to the list...
        if (this.autoSort) {
            this.data.add(-index - 1, new XYDataItem(x, y));
        } else {
            this.data.add(new XYDataItem(x, y));
        }

        // check if this addition will exceed the maximum item count...
        if (getItemCount() > this.maximumItemCount) {
            this.data.remove(0);
        }
    }
    fireSeriesChanged();
    return overwritten;
}

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

/**
 * Adds or updates an item in the series and sends a
 * {@link SeriesChangeEvent} to all registered listeners.
 *
 * @param x  the x-value (<code>null</code> not permitted).
 * @param y  the y-value (<code>null</code> permitted).
 *
 * @return A copy of the overwritten data item, or
 *         <code>null</code> if noitem was overwritten.
 *//*from  w w  w . jav  a  2  s.co  m*/
public XYDataItem addOrUpdate(Number x, Number y) {
    if (x == null) {
        throw new IllegalArgumentException("Null 'x' argument.");
    }
    if (this.allowDuplicateXValues) {
        add(x, y);
        return null;
    }

    // if we get to here, we know that duplicate X values are not permitted
    XYDataItem overwritten = null;
    int index = indexOf(x);
    if (index >= 0) {
        XYDataItem existing = (XYDataItem) this.data.get(index);
        try {
            overwritten = (XYDataItem) existing.clone();
        } catch (CloneNotSupportedException e) {
            throw new SeriesException("Couldn't clone XYDataItem!");
        }
        existing.setY(y);
    } else {

        // if the series is sorted, the negative index is a result from
        // Collections.binarySearch() and tells us where to insert the
        // new item...otherwise it will be just -1 and we should just
        // append the value to the list...
        if (this.autoSort) {
            this.data.add(-index - 1, new XYDataItem(x, y));
        } else {
            this.data.add(new XYDataItem(x, y));
        }

        // check if this addition will exceed the maximum item count...
        if (getItemCount() > this.maximumItemCount) {
            this.data.remove(0);
        }
    }
    fireSeriesChanged();
    return overwritten;
}

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

/**
 * Updates the value of an item in the series and sends a
 * {@link SeriesChangeEvent} to all registered listeners.
 *
 * @param index  the item (zero based index).
 * @param y  the new value (<code>null</code> permitted).
 *
 * @deprecated Renamed {@link #updateByIndex(int, Number)} to avoid
 *         confusion with the {@link #update(Number, Number)} method.
 *//*w  ww . j  ava 2  s .c  o m*/
public void update(int index, Number y) {
    XYDataItem item = getRawDataItem(index);

    // figure out if we need to iterate through all the y-values
    boolean iterate = false;
    double oldY = item.getYValue();
    if (!Double.isNaN(oldY)) {
        iterate = oldY <= this.minY || oldY >= this.maxY;
    }
    item.setY(y);

    if (iterate) {
        findBoundsByIteration();
    } else if (y != null) {
        double yy = y.doubleValue();
        this.minY = minIgnoreNaN(this.minY, yy);
        this.maxY = maxIgnoreNaN(this.maxY, yy);
    }
    fireSeriesChanged();
}