Example usage for org.jfree.data.xy XYSeriesCollection removeSeries

List of usage examples for org.jfree.data.xy XYSeriesCollection removeSeries

Introduction

In this page you can find the example usage for org.jfree.data.xy XYSeriesCollection removeSeries.

Prototype

public void removeSeries(XYSeries series) 

Source Link

Document

Removes a series from the collection and sends a DatasetChangeEvent to all registered listeners.

Usage

From source file:edu.gmu.cs.sim.util.media.chart.TimeSeriesChartGenerator.java

public void removeSeries(int index) {
    super.removeSeries(index);
    XYSeriesCollection xysc = (XYSeriesCollection) getSeriesDataset();
    xysc.removeSeries(index);
}

From source file:jamel.gui.charts.InstantScatterChart.java

/**
 * Sets the time range./*from w w w.  j a  v  a2  s  . co  m*/
 * 
 * @param lower  the lower date limit (not used).
 * @param upper  the upper date limit (not used).
 */
public void setTimeRange(Date lower, Date upper) {
    XYSeriesCollection dataset = (XYSeriesCollection) ((XYPlot) this.getPlot()).getDataset();
    XYSeries newSeries = Circuit.getCircuit().getCrossSectionSeries().get(xLabel, yLabel);
    if (newSeries == null)
        return;
    try {
        dataset.removeSeries(0);
    } catch (IllegalArgumentException i) {
    }
    dataset.addSeries(newSeries);
}

From source file:org.jfree.data.xy.junit.XYSeriesCollectionTest.java

/**
 * Some basic checks for the removeSeries() method.
 *///from w w  w .java2  s .c om
public void testRemoveSeries() {
    XYSeriesCollection c = new XYSeriesCollection();
    XYSeries s1 = new XYSeries("s1");
    c.addSeries(s1);
    c.removeSeries(0);
    assertEquals(0, c.getSeriesCount());
    c.addSeries(s1);

    boolean pass = false;
    try {
        c.removeSeries(-1);
    } catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);

    pass = false;
    try {
        c.removeSeries(1);
    } catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);
}

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

/**
 * Some basic checks for the removeSeries() method.
 *//*w w  w . j a  va 2  s. c  o m*/
@Test
public void testRemoveSeries() {
    XYSeriesCollection c = new XYSeriesCollection();
    XYSeries s1 = new XYSeries("s1");
    c.addSeries(s1);
    c.removeSeries(0);
    assertEquals(0, c.getSeriesCount());
    c.addSeries(s1);

    try {
        c.removeSeries(-1);
        fail("Should have thrown IndexOutOfBoundsException on negative key");
    } catch (IllegalArgumentException e) {
        assertEquals("Series index out of bounds.", e.getMessage());
    }

    try {
        c.removeSeries(1);
        fail("Should have thrown IndexOutOfBoundsException on key out of range");
    } catch (IllegalArgumentException e) {
        assertEquals("Series index out of bounds.", e.getMessage());
    }
}

From source file:speedbagalg.OscopeView.java

private void plotXCheckBoxStateChanged(javax.swing.event.ChangeEvent evt)//GEN-FIRST:event_plotXCheckBoxStateChanged
{//GEN-HEADEREND:event_plotXCheckBoxStateChanged
    if (plotX == plotXCheckBox.isSelected())
        return;/*w  w w . j  av a2s. c om*/
    plotX = plotXCheckBox.isSelected();
    XYSeriesCollection s = (XYSeriesCollection) chart.getXYPlot().getDataset();
    if (plotX)
        s.addSeries(xData);
    else
        s.removeSeries(xData);
}

From source file:speedbagalg.OscopeView.java

private void plotYCheckBoxStateChanged(javax.swing.event.ChangeEvent evt)//GEN-FIRST:event_plotYCheckBoxStateChanged
{//GEN-HEADEREND:event_plotYCheckBoxStateChanged
    if (plotY == plotYCheckBox.isSelected())
        return;//from w  w w  . j  a  v a  2 s.  co  m
    plotY = plotYCheckBox.isSelected();
    XYSeriesCollection s = (XYSeriesCollection) chart.getXYPlot().getDataset();
    if (plotY)
        s.addSeries(yData);
    else
        s.removeSeries(yData);
}

From source file:speedbagalg.OscopeView.java

private void plotZCheckBoxStateChanged(javax.swing.event.ChangeEvent evt)//GEN-FIRST:event_plotZCheckBoxStateChanged
{//GEN-HEADEREND:event_plotZCheckBoxStateChanged
    if (plotZ == plotZCheckBox.isSelected())
        return;/* ww  w  .  j a  v  a  2  s .  c om*/
    plotZ = plotZCheckBox.isSelected();
    XYSeriesCollection s = (XYSeriesCollection) chart.getXYPlot().getDataset();
    if (plotZ)
        s.addSeries(zData);
    else
        s.removeSeries(zData);
}

From source file:org.jfree.data.xy.junit.XYSeriesCollectionTest.java

/**
 * Some tests for the indexOf() method./*from   w  w w .j  av  a 2 s .co m*/
 */
public void testIndexOf() {
    XYSeries s1 = new XYSeries("S1");
    XYSeries s2 = new XYSeries("S2");
    XYSeriesCollection dataset = new XYSeriesCollection();
    assertEquals(-1, dataset.indexOf(s1));
    assertEquals(-1, dataset.indexOf(s2));

    dataset.addSeries(s1);
    assertEquals(0, dataset.indexOf(s1));
    assertEquals(-1, dataset.indexOf(s2));

    dataset.addSeries(s2);
    assertEquals(0, dataset.indexOf(s1));
    assertEquals(1, dataset.indexOf(s2));

    dataset.removeSeries(s1);
    assertEquals(-1, dataset.indexOf(s1));
    assertEquals(0, dataset.indexOf(s2));

    XYSeries s2b = new XYSeries("S2");
    assertEquals(0, dataset.indexOf(s2b));
}

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

/**
 * Some tests for the indexOf() method.//from  w w w  . j  a  va2  s.c o m
 */
@Test
public void testIndexOf() {
    XYSeries s1 = new XYSeries("S1");
    XYSeries s2 = new XYSeries("S2");
    XYSeriesCollection dataset = new XYSeriesCollection();
    assertEquals(-1, dataset.indexOf(s1));
    assertEquals(-1, dataset.indexOf(s2));

    dataset.addSeries(s1);
    assertEquals(0, dataset.indexOf(s1));
    assertEquals(-1, dataset.indexOf(s2));

    dataset.addSeries(s2);
    assertEquals(0, dataset.indexOf(s1));
    assertEquals(1, dataset.indexOf(s2));

    dataset.removeSeries(s1);
    assertEquals(-1, dataset.indexOf(s1));
    assertEquals(0, dataset.indexOf(s2));

    XYSeries s2b = new XYSeries("S2");
    assertEquals(0, dataset.indexOf(s2b));
}

From source file:com.ivli.roim.controls.ChartView.java

@Override
public void OverlayChanged(OverlayChangeEvent anEvt) {
    LOG.debug(anEvt);/*from  w w  w  .  ja v a  2 s . co  m*/

    if (anEvt.getObject() instanceof ROI) {
        XYSeriesCollection col = ((XYSeriesCollection) iPlot.getDataset());
        final OverlayManager mgr = (OverlayManager) anEvt.getSource();

        switch (anEvt.getCode()) {
        case CREATED: {
            assert (0 > col.indexOf(anEvt.getObject().getName()));

            final XYSeries s = new XYSeries(anEvt.getObject().getName(), true, false);
            final ISeries c = ((ROI) anEvt.getObject()).getSeries(Measurement.DENSITY);

            IMultiframeImage img = mgr.getImage();

            assert (c.size() == img.getTimeSliceVector().getNumFrames());

            for (int n = 0; n < c.size(); ++n)
                s.add(img.getTimeSliceVector().getSlices().get(n) / 1000., c.get(n));

            ((XYSeriesCollection) iPlot.getDataset()).addSeries(s);
            iPlot.getRenderer().setSeriesPaint(col.indexOf(anEvt.getObject().getName()),
                    ((ROI) anEvt.getObject()).getColor());
        }
            break;

        case DELETED: {
            final int ndx = col.indexOf(anEvt.getObject().getName());
            col.removeSeries(ndx);
        }
            break;

        case MOVED: {//fall-through                                                                      
            final int ndx = col.indexOf(anEvt.getObject().getName());
            ISeries c = ((ROI) anEvt.getObject()).getSeries(Measurement.DENSITY);
            XYSeries s = col.getSeries(ndx);
            s.setNotify(false);
            s.clear();

            for (int n = 0; n < c.size(); ++n) {
                long dur = mgr.getImage().getTimeSliceVector().getSlices().get(n) / 1000;
                s.add(dur, c.get(n));
            }
            s.setNotify(true);
            //s.fireSeriesChanged();

        }
            break;

        case COLOR_CHANGED: {
            assert (anEvt.getExtra() instanceof java.awt.Color);
            final int ndx = col.indexOf(anEvt.getObject().getName());
            iPlot.getRenderer().setSeriesPaint(ndx, ((ROI) anEvt.getObject()).getColor());
        }
            break;

        case NAME_CHANGED: {
            assert (anEvt.getExtra() instanceof String);
            LOG.debug("ROI" + (String) anEvt.getExtra() + "name changed to " + anEvt.getObject().getName());

            final int ndx = col.indexOf(((String) anEvt.getExtra()));

            col.getSeries(ndx).setKey(anEvt.getObject().getName());
            /* this is a work-around the case when two or more ROI have the same names (user mistakenly renamed) 
             * when this mistake is corrected it might happen the colors of curves does not match colors of corresponding ROI 
             */
            iPlot.getRenderer().setSeriesPaint(ndx, ((ROI) anEvt.getObject()).getColor());

        }
            break;

        default:
            ///throw new java.lang.IllegalArgumentException();    
            break;
        }
    }
}