Example usage for org.jfree.data.xy YIntervalSeriesCollection addSeries

List of usage examples for org.jfree.data.xy YIntervalSeriesCollection addSeries

Introduction

In this page you can find the example usage for org.jfree.data.xy YIntervalSeriesCollection addSeries.

Prototype

public void addSeries(YIntervalSeries series) 

Source Link

Document

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

Usage

From source file:de.bund.bfr.knime.nls.chart.ChartCreator.java

private static XYDataset createDataSet(String key, double[][] points, double[][] errors) {
    if (points != null) {
        if (errors != null) {
            YIntervalSeriesCollection functionDataset = new YIntervalSeriesCollection();
            YIntervalSeries series = new YIntervalSeries(key);

            for (int j = 0; j < points[0].length; j++) {
                double error = Double.isFinite(errors[1][j]) ? errors[1][j] : 0.0;

                series.add(points[0][j], points[1][j], points[1][j] - error, points[1][j] + error);
            }/*from w w  w  .j  a  v  a 2s  .co m*/

            functionDataset.addSeries(series);

            return functionDataset;
        } else {
            DefaultXYDataset functionDataset = new DefaultXYDataset();

            functionDataset.addSeries(key, points);

            return functionDataset;
        }
    }

    return null;
}

From source file:it.unibo.alchemist.boundary.gui.asmc.SimplePlot.java

@Override
public void batchDone(final double[][] values, final double lower, final double upper, final int sampleSize) {
    this.removeAll();
    final YIntervalSeries series = new YIntervalSeries("Probability of condition satisfaction vs. time");
    for (final double[] value : values) {
        series.add(value[0], value[1], value[2], value[TRE]);
    }//from w  ww  . j  a va  2 s  . com
    final YIntervalSeriesCollection data = new YIntervalSeriesCollection();
    data.addSeries(series);
    final JFreeChart chart = ChartFactory.createXYLineChart("", "X", "Y", data, PlotOrientation.VERTICAL, true,
            true, false);
    XYItemRenderer renderer;
    switch (currentRenderer) {
    case 1:
        renderer = new YIntervalRenderer();
        break;
    case 0:
    default:
        renderer = new DeviationRenderer(true, false);
    }
    final XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(renderer);
    plot.getDomainAxis().setLowerBound(lower);
    plot.getDomainAxis().setUpperBound(upper);
    plot.getRangeAxis().setUpperBound(1.0);
    plot.getRangeAxis().setLowerBound(0.0);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(DIMENSION);
    this.setLayout(new BorderLayout());
    this.add(chartPanel, BorderLayout.NORTH);
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            chartPanel.getRootPane().validate();
        }
    });
}

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

/**
 * A test for bug report 1170825 (originally affected XYSeriesCollection,
 * this test is just copied over).//from   ww  w.j  av  a 2 s.co m
 */
@Test
public void test1170825() {
    YIntervalSeries s1 = new YIntervalSeries("Series1");
    YIntervalSeriesCollection dataset = new YIntervalSeriesCollection();
    dataset.addSeries(s1);
    try {
        /* XYSeries s = */ dataset.getSeries(1);
    } catch (IllegalArgumentException e) {
        // correct outcome
    } catch (IndexOutOfBoundsException e) {
        assertTrue(false); // wrong outcome
    }
}

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

/**
 * A test for bug report 1170825 (originally affected XYSeriesCollection,
 * this test is just copied over)./*from  w w  w .  j a  v a2s  .c  om*/
 */
public void test1170825() {
    YIntervalSeries s1 = new YIntervalSeries("Series1");
    YIntervalSeriesCollection dataset = new YIntervalSeriesCollection();
    dataset.addSeries(s1);
    try {
        /* XYSeries s = */ dataset.getSeries(1);
    } catch (IllegalArgumentException e) {
        // correct outcome
    } catch (IndexOutOfBoundsException e) {
        assertTrue(false); // wrong outcome
    }
}

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

/**
 * Some basic checks for the removeSeries() method.
 *//*from  w  w w.j  a v a 2s. c  o  m*/
@Test
public void testRemoveSeries() {
    YIntervalSeriesCollection c = new YIntervalSeriesCollection();
    YIntervalSeries s1 = new YIntervalSeries("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.YIntervalSeriesCollectionTest.java

/**
 * Confirm that cloning works./*from   ww  w.  ja v a  2  s.com*/
 */
@Test
public void testCloning() throws CloneNotSupportedException {
    YIntervalSeriesCollection c1 = new YIntervalSeriesCollection();
    YIntervalSeries s1 = new YIntervalSeries("Series");
    s1.add(1.0, 1.1, 1.2, 1.3);
    c1.addSeries(s1);
    YIntervalSeriesCollection c2 = (YIntervalSeriesCollection) c1.clone();
    assertTrue(c1 != c2);
    assertTrue(c1.getClass() == c2.getClass());
    assertTrue(c1.equals(c2));

    // check independence
    s1.setDescription("XYZ");
    assertFalse(c1.equals(c2));
}

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

/**
 * Some basic checks for the removeSeries() method.
 *///  w  w  w . j ava  2 s .c  om
public void testRemoveSeries() {
    YIntervalSeriesCollection c = new YIntervalSeriesCollection();
    YIntervalSeries s1 = new YIntervalSeries("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:com.att.aro.ui.view.diagnostictab.plot.DLPacketPlot.java

@Override
public void populate(XYPlot plot, AROTraceData analysis) {

    LinkedHashMap<Color, PacketSeries> dlDatasets = new LinkedHashMap<Color, PacketSeries>();

    AnalysisFilter filter = null;/*w ww  .  j  av  a 2 s  .  co  m*/
    //      logger.info("isDownloadPacket(): "+ isDownloadPacket());
    if (analysis != null) {
        filter = analysis.getAnalyzerResult().getFilter();
        for (Session session : analysis.getAnalyzerResult().getSessionlist()) {
            addSeries(session, dlDatasets, filter);
        }
    }
    // Create the XY data set
    YIntervalSeriesCollection coll = new YIntervalSeriesCollection();
    XYItemRenderer renderer = plot.getRenderer();
    for (PacketSeries series : dlDatasets.values()) {
        coll.addSeries(series);
        renderer.setSeriesPaint(coll.indexOf(series.getKey()), series.getColor());
    }

    // Create tooltip generator
    renderer.setBaseToolTipGenerator(new PacketToolTipGenerator());

    plot.setDataset(coll);

    //      return plot;
}

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

/**
 * Confirm that cloning works.//w  ww.  ja va 2s  . c  o m
 */
public void testCloning() {
    YIntervalSeriesCollection c1 = new YIntervalSeriesCollection();
    YIntervalSeries s1 = new YIntervalSeries("Series");
    s1.add(1.0, 1.1, 1.2, 1.3);
    c1.addSeries(s1);
    YIntervalSeriesCollection c2 = null;
    try {
        c2 = (YIntervalSeriesCollection) c1.clone();
    } catch (CloneNotSupportedException e) {
        e.printStackTrace();
    }
    assertTrue(c1 != c2);
    assertTrue(c1.getClass() == c2.getClass());
    assertTrue(c1.equals(c2));

    // check independence
    s1.setDescription("XYZ");
    assertFalse(c1.equals(c2));
}

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

/**
 * Confirm that the equals method can distinguish all the required fields.
 *//*from   ww  w .j  a  va2  s.  c o  m*/
@Test
public void testEquals() {
    YIntervalSeriesCollection c1 = new YIntervalSeriesCollection();
    YIntervalSeriesCollection c2 = new YIntervalSeriesCollection();
    assertEquals(c1, c2);

    // add a series
    YIntervalSeries s1 = new YIntervalSeries("Series");
    s1.add(1.0, 1.1, 1.2, 1.3);
    c1.addSeries(s1);
    assertFalse(c1.equals(c2));
    YIntervalSeries s2 = new YIntervalSeries("Series");
    s2.add(1.0, 1.1, 1.2, 1.3);
    c2.addSeries(s2);
    assertTrue(c1.equals(c2));

    // add an empty series
    c1.addSeries(new YIntervalSeries("Empty Series"));
    assertFalse(c1.equals(c2));
    c2.addSeries(new YIntervalSeries("Empty Series"));
    assertTrue(c1.equals(c2));
}