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

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

Introduction

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

Prototype

public YIntervalSeriesCollection() 

Source Link

Document

Creates a new instance of YIntervalSeriesCollection.

Usage

From source file:de.tud.kom.p2psim.impl.skynet.visualization.MetricsPlot.java

private void createChartPanel(String title, long time) {
    YIntervalSeriesCollection dataset = new YIntervalSeriesCollection();
    chart = ChartFactory.createTimeSeriesChart(title, X_AXIS_TITLE, "", dataset, true, true, true);
    XYPlot plot = (XYPlot) chart.getPlot();

    DeviationRenderer errorRenderer = new DeviationRenderer();
    errorRenderer.setShapesVisible(false);
    errorRenderer.setLinesVisible(true);
    errorRenderer.setAlpha(0.0f);// w ww.j a  va  2  s  . com
    // errorRenderer.setDrawYError(false);
    // errorRenderer.setDrawXError(false);
    plot.setRenderer(errorRenderer);

    plot.setBackgroundPaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.DARK_GRAY);
    plot.setDomainGridlinePaint(Color.DARK_GRAY);
    upperDomainBound = (time / 1000) + ((interval - 1) * step / 1000);
    DateAxis domain = (DateAxis) plot.getDomainAxis();
    domain.setAutoRange(false);
    domain.setRange((time / 1000), upperDomainBound);
    RelativeDateFormat rdf = new RelativeDateFormat();
    rdf.setHourSuffix(":");
    rdf.setMinuteSuffix(":");
    rdf.setSecondSuffix("");
    rdf.setSecondFormatter(new DecimalFormat("0"));
    domain.setDateFormatOverride(rdf);
    plot.setDomainAxis(domain);
    plotPanel = new ChartPanel(chart, true);
    setSizeOfComponent(plotPanel, new Dimension(plotWidth, plotHeight));
    container.add(plotPanel, BorderLayout.CENTER);
    container.add(createRadioBoxes(visType == VisualizationType.Metric), BorderLayout.SOUTH);
    setSizeOfComponent(container, new Dimension(plotWidth, plotHeight + boxOffset));
}

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

/**
 * Some basic checks for the removeSeries() method.
 *//*from   w w  w.  ja v a2s .com*/
@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.junit.YIntervalSeriesCollectionTest.java

/**
 * Verify that this class implements {@link PublicCloneable}.
 *///from  w ww  .  j  av  a2 s  .co  m
public void testPublicCloneable() {
    YIntervalSeriesCollection c1 = new YIntervalSeriesCollection();
    assertTrue(c1 instanceof PublicCloneable);
}

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

/**
 * Serialize an instance, restore it, and check for equality.
 *//*from www . j  a v a 2 s.  co m*/
public void testSerialization() {
    YIntervalSeriesCollection c1 = new YIntervalSeriesCollection();
    YIntervalSeries s1 = new YIntervalSeries("Series");
    s1.add(1.0, 1.1, 1.2, 1.3);
    YIntervalSeriesCollection c2 = null;

    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(c1);
        out.close();

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        c2 = (YIntervalSeriesCollection) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(c1, c2);
}

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   w  w  w  .  j  a v  a 2s.  com*/
 */
@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

/**
 * Some basic checks for the removeSeries() method.
 */// w w  w .  j  av a 2  s.  c  o  m
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.rapidminer.gui.viewer.ROCChartPlotter.java

private void prepareData() {

    this.dataset = new YIntervalSeriesCollection();

    Iterator<Map.Entry<String, List<ROCData>>> r = rocDataLists.entrySet().iterator();
    boolean showThresholds = true;
    if (rocDataLists.size() > 1) {
        showThresholds = false;//ww w.j  a  v a 2 s  .  c o m
    }

    while (r.hasNext()) {
        Map.Entry<String, List<ROCData>> entry = r.next();
        YIntervalSeries rocSeries = new YIntervalSeries(entry.getKey());
        YIntervalSeries thresholdSeries = new YIntervalSeries(entry.getKey() + " (Thresholds)");
        List<ROCData> dataList = entry.getValue();
        for (int i = 0; i <= NUMBER_OF_POINTS; i++) {

            double rocSum = 0.0d;
            double rocSquaredSum = 0.0d;
            double thresholdSum = 0.0d;
            double thresholdSquaredSum = 0.0d;
            for (ROCData data : dataList) {
                double rocValue = data.getInterpolatedTruePositives(i / (double) NUMBER_OF_POINTS)
                        / data.getTotalPositives();
                rocSum += rocValue;
                rocSquaredSum += rocValue * rocValue;

                double thresholdValue = data.getInterpolatedThreshold(i / (double) NUMBER_OF_POINTS);
                thresholdSum += thresholdValue;
                thresholdSquaredSum += thresholdValue * thresholdValue;
            }

            double rocMean = rocSum / dataList.size();
            double rocDeviation = Math.sqrt(rocSquaredSum / dataList.size() - (rocMean * rocMean));
            rocSeries.add(i / (double) NUMBER_OF_POINTS, rocMean, rocMean - rocDeviation,
                    rocMean + rocDeviation);

            double thresholdMean = thresholdSum / dataList.size();
            double thresholdDeviation = Math
                    .sqrt(thresholdSquaredSum / dataList.size() - (thresholdMean * thresholdMean));
            thresholdSeries.add(i / (double) NUMBER_OF_POINTS, thresholdMean,
                    thresholdMean - thresholdDeviation, thresholdMean + thresholdDeviation);

        }
        dataset.addSeries(rocSeries);

        if (showThresholds) {
            dataset.addSeries(thresholdSeries);
        }
    }
}

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  ww w  .  j  ava 2s .  c  o  m*/
 */
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:de.tud.kom.p2psim.impl.skynet.visualization.MetricsPlot.java

private void updateChartPanel(String plotTitle) {
    XYPlot plot = (XYPlot) chart.getPlot();
    YIntervalSeriesCollection dataset = new YIntervalSeriesCollection();// (YIntervalSeriesCollection)
    // plot.getDataset()
    String[] names = displayedSeries.keySet().toArray(new String[displayedSeries.keySet().size()]);
    Arrays.sort(names, null);//w w w.  j ava  2s .c o  m
    if (!autoScrolling && displayedSeries.get(names[0]).getDataSeries().getItemCount() == displayedSeries
            .get(names[0]).getDataSeries().getMaximumItemCount()) {
        autoScrolling = true;
        DateAxis domain = (DateAxis) plot.getDomainAxis();
        domain.setAutoRange(true);
        plot.setDomainAxis(domain);
    }
    for (int i = 0; i < names.length; i++) {
        if (names[i].startsWith("Min_")) {
            if (showMin)
                dataset.addSeries(displayedSeries.get(names[i]).getDataSeries());
        } else if (names[i].startsWith("Max_")) {
            if (showMax)
                dataset.addSeries(displayedSeries.get(names[i]).getDataSeries());
        } else {
            dataset.addSeries(displayedSeries.get(names[i]).getDataSeries());
        }

    }
    plot.setDataset(dataset);
    plot.setRenderer(configureRendererForDataSet(plot.getRenderer(), dataset));
    plotPanel.setChart(chart);
    setSizeOfComponent(plotPanel, new Dimension(plotWidth, plotHeight));
    container.add(plotPanel, BorderLayout.CENTER);
    setSizeOfComponent(container, new Dimension(plotWidth, plotHeight + boxOffset));
}

From source file:com.rapidminer.gui.plotter.charts.DeviationChartPlotter.java

private int prepareData() {
    // calculate min and max
    int columns = this.dataTable.getNumberOfColumns();
    double[] min = new double[columns];
    double[] max = new double[columns];
    for (int c = 0; c < columns; c++) {
        min[c] = Double.POSITIVE_INFINITY;
        max[c] = Double.NEGATIVE_INFINITY;
    }/*from  w  w w .j  a va 2  s  .c  om*/

    synchronized (dataTable) {
        Iterator<DataTableRow> i = dataTable.iterator();
        while (i.hasNext()) {
            DataTableRow row = i.next();
            for (int c = 0; c < dataTable.getNumberOfColumns(); c++) {
                double value = row.getValue(c);
                min[c] = MathFunctions.robustMin(min[c], value);
                max[c] = MathFunctions.robustMax(max[c], value);
            }
        }
    }

    synchronized (dataTable) {
        this.dataset = new YIntervalSeriesCollection();
        if (colorColumn >= 0 && dataTable.isNominal(colorColumn)) {
            for (int v = 0; v < dataTable.getNumberOfValues(colorColumn); v++) {
                String valueName = dataTable.mapIndex(colorColumn, v);
                YIntervalSeries series = new YIntervalSeries(valueName);
                boolean first = true;
                List<String> domainValues = new LinkedList<String>();
                for (int column = 0; column < dataTable.getNumberOfColumns(); column++) {
                    if (!dataTable.isSpecial(column) && column != colorColumn) {
                        Iterator<DataTableRow> i = this.dataTable.iterator();
                        double sum = 0.0d;
                        double squaredSum = 0.0d;
                        int counter = 0;
                        while (i.hasNext()) {
                            DataTableRow row = i.next();
                            if (row.getValue(colorColumn) != v) {
                                continue;
                            }
                            double value = row.getValue(column);
                            sum += value;
                            squaredSum += value * value;
                            counter++;
                        }

                        double mean = sum / counter;
                        double deviation = Math.sqrt(squaredSum / counter - mean * mean);
                        if (isLocalNormalized()) {
                            mean = (mean - min[column]) / (max[column] - min[column]);
                            deviation = (deviation - min[column]) / (max[column] - min[column]);
                        }
                        series.add(column, mean, mean - deviation, mean + deviation);
                        domainValues.add(dataTable.getColumnName(column));
                    }
                }
                if (first) {
                    this.domainAxisMap = new String[domainValues.size()];
                    domainValues.toArray(this.domainAxisMap);
                }
                first = false;
                dataset.addSeries(series);
            }
            return dataTable.getNumberOfValues(colorColumn);
        } else {
            YIntervalSeries series = new YIntervalSeries(dataTable.getName());
            List<String> domainValues = new LinkedList<String>();
            for (int column = 0; column < dataTable.getNumberOfColumns(); column++) {
                if (!dataTable.isSpecial(column) && column != colorColumn) {
                    Iterator<DataTableRow> i = this.dataTable.iterator();
                    double sum = 0.0d;
                    double squaredSum = 0.0d;
                    int counter = 0;
                    while (i.hasNext()) {
                        DataTableRow row = i.next();
                        double value = row.getValue(column);
                        sum += value;
                        squaredSum += value * value;
                        counter++;
                    }

                    double mean = sum / counter;
                    double deviation = Math.sqrt(squaredSum / counter - mean * mean);
                    if (isLocalNormalized()) {
                        mean = (mean - min[column]) / (max[column] - min[column]);
                        // deviation = (deviation - min[column]) / (max[column] - min[column]);
                    }
                    series.add(column, mean, mean - deviation, mean + deviation);
                    domainValues.add(dataTable.getColumnName(column));
                }
            }
            dataset.addSeries(series);
            this.domainAxisMap = new String[domainValues.size()];
            domainValues.toArray(this.domainAxisMap);
            return 0;
        }
    }
}