Example usage for org.jfree.data.statistics DefaultBoxAndWhiskerCategoryDataset DefaultBoxAndWhiskerCategoryDataset

List of usage examples for org.jfree.data.statistics DefaultBoxAndWhiskerCategoryDataset DefaultBoxAndWhiskerCategoryDataset

Introduction

In this page you can find the example usage for org.jfree.data.statistics DefaultBoxAndWhiskerCategoryDataset DefaultBoxAndWhiskerCategoryDataset.

Prototype

public DefaultBoxAndWhiskerCategoryDataset() 

Source Link

Document

Creates a new dataset.

Usage

From source file:de.hs.mannheim.modUro.controller.diagram.BoxAndWhiskerPlotController.java

/**
 * Creates dataset for BoxWhiskerPlot.//from ww w .ja va  2s .  co m
 *
 * @return
 */
private BoxAndWhiskerCategoryDataset createDataset() {

    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();

    List<String> sortedModels = new ArrayList<>(models);
    sortedModels.sort(String::compareTo);
    for (String model : sortedModels) {
        StatisticValues stat = stats.get(model);
        BoxAndWhiskerItem item = new BoxAndWhiskerItem(stat.getMean(), stat.getSecondPercentile(),
                stat.getFirstPercentile(), stat.getLastPercentile(), stat.getMin(), stat.getMax(),
                stat.getMin(), stat.getMax(), new ArrayList<>());
        // Second parameter is the row key (?), using always the same works:
        dataset.add(item, "", model);
    }
    return dataset;
}

From source file:net.sf.maltcms.chromaui.normalization.spi.charts.PeakGroupBoxPlot.java

public List<JFreeChart> createChart() {
    List<JFreeChart> charts = new ArrayList<>();
    LinkedHashSet<ITreatmentGroupDescriptor> treatmentGroups = new LinkedHashSet<>(
            project.getTreatmentGroups());
    List<CategoryPlot> plots = new LinkedList<>();
    for (IPeakGroupDescriptor pgd : pgdl) {
        LinkedHashMap<ITreatmentGroupDescriptor, HashSet<IPeakAnnotationDescriptor>> map = new LinkedHashMap<>();
        for (ITreatmentGroupDescriptor itgd : treatmentGroups) {
            map.put(itgd, new LinkedHashSet<IPeakAnnotationDescriptor>());
        }//from  www  .j  av  a2 s .co m
        List<IPeakAnnotationDescriptor> descriptors = pgd.getPeakAnnotationDescriptors();

        DefaultBoxAndWhiskerCategoryDataset baw = new DefaultBoxAndWhiskerCategoryDataset();
        for (IPeakAnnotationDescriptor ipad : descriptors) {
            ITreatmentGroupDescriptor treatmentGroup = ipad.getChromatogramDescriptor().getTreatmentGroup();
            HashSet<IPeakAnnotationDescriptor> descr = map.get(treatmentGroup);
            if (descr == null) {
                descr = new HashSet<>();
                map.put(treatmentGroup, descr);
            }
            descr.add(ipad);
        }
        List<Color> colors = new LinkedList<>();
        for (ITreatmentGroupDescriptor tgd : map.keySet()) {
            String name = getPeakName(pgd);
            baw.add(createBoxAndWhiskerItem(map.get(tgd)), tgd.getName() + " (" + map.get(tgd).size() + ")",
                    name);
            colors.add(tgd.getColor());
        }
        BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
        renderer.setFillBox(true);
        renderer.setMeanVisible(false);
        renderer.setMedianVisible(true);
        renderer.setArtifactPaint(new Color(0, 0, 0, 128));
        renderer.setMaximumBarWidth(0.1);
        renderer.setUseOutlinePaintForWhiskers(false);
        //            renderer.setAutoPopulateSeriesFillPaint(true);
        //            renderer.setAutoPopulateSeriesPaint(true);
        //            renderer.setAutoPopulateSeriesOutlinePaint(true);
        CategoryPlot cp = new CategoryPlot(baw, new CategoryAxis("Treatment Groups"),
                new NumberAxis("Normalized Peak Area"), renderer);
        Logger.getLogger(getClass().getName()).log(Level.INFO, "Setting {0} colors!", colors.size());
        ChartCustomizer.setSeriesColors(cp, 0.6f, colors);
        //            ChartCustomizer.setSeriesColors(cp, 0.9f,colors);
        plots.add(cp);
        JFreeChart chart = new JFreeChart(cp);
        chart.setTitle(
                "Peak group " + pgd.getDisplayName() + " size: " + pgd.getPeakAnnotationDescriptors().size());
        charts.add(chart);
    }
    //        CategoryAxis ca = new CategoryAxis("Treatment Groups");
    //        NumberAxis va = new NumberAxis("Normalized Peak Area");
    //        CombinedDomainCategoryPlot cdcp = new CombinedDomainCategoryPlot(ca);
    //        for (CategoryPlot cp : plots) {
    //            cp.setRangeAxis(va);
    //            cdcp.add(cp);
    //            break;
    //        }
    //        return new JFreeChart(cdcp);
    return charts;
}

From source file:org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDatasetTest.java

/**
 * Serialize an instance, restore it, and check for equality.
 *//*from w w  w  .  j  av  a  2s.c o m*/
@Test
public void testSerialization() {
    DefaultBoxAndWhiskerCategoryDataset d1 = new DefaultBoxAndWhiskerCategoryDataset();
    d1.add(new BoxAndWhiskerItem(new Double(1.0), new Double(2.0), new Double(3.0), new Double(4.0),
            new Double(5.0), new Double(6.0), new Double(7.0), new Double(8.0), new ArrayList()), "ROW1",
            "COLUMN1");
    DefaultBoxAndWhiskerCategoryDataset d2 = (DefaultBoxAndWhiskerCategoryDataset) TestUtilities.serialised(d1);
    assertEquals(d1, d2);
}

From source file:umontreal.iro.lecuyer.charts.BoxSeriesCollection.java

/**
 * Creates a new <TT>BoxSeriesCollection</TT> instance with default
 *    parameters and given data series. The input parameter represents series
 *    of point sets.//from ww w.  j a  v a2  s . c  o  m
 * 
 * @param data series of point sets.
 * 
 * 
 */
public BoxSeriesCollection(double[]... data) {
    renderer = new BoxAndWhiskerRenderer();
    seriesCollection = new DefaultBoxAndWhiskerCategoryDataset();

    DefaultBoxAndWhiskerCategoryDataset tempSeriesCollection = (DefaultBoxAndWhiskerCategoryDataset) seriesCollection;

    for (int i = 0; i < data.length; i++) {
        if (data[i].length == 0)
            throw new IllegalArgumentException("Unable to render the plot. data[" + i + "] contains no row");
        final List<Double> list = new ArrayList<Double>();
        for (int j = 0; j < data[i].length - 1; j++)
            list.add(data[i][j]);
        tempSeriesCollection.add(list, 0, "Serie " + i);
        list.clear();
    }
    ((BoxAndWhiskerRenderer) renderer).setMaximumBarWidth(BARWIDTH);
}

From source file:edu.ucla.stat.SOCR.chart.demo.BoxAndWhiskerChartDemo3.java

/**
 * Returns a sample dataset.//from   ww w .  j  a v  a2  s  .  c o  m
 * 
 * @return The dataset.
 */
protected BoxAndWhiskerCategoryDataset createDataset(boolean isDemo) {
    if (isDemo) {
        rangeLabel = "Value";
        SERIES_COUNT = 3;
        // CATEGORY_COUNT = 2;
        VALUE_COUNT = 10;
        values_storage = new String[SERIES_COUNT][CATEGORY_COUNT];

        DefaultBoxAndWhiskerCategoryDataset result = new DefaultBoxAndWhiskerCategoryDataset();

        for (int s = 0; s < SERIES_COUNT; s++) {
            for (int c = 0; c < CATEGORY_COUNT; c++) {
                List values = createValueList(0, 20.0, VALUE_COUNT);
                values_storage[s][c] = vs;
                result.add(values, "Series " + s, "Category " + c);
            }
        }
        return result;
    } else
        return super.createDataset(false);
}

From source file:org.jax.bham.test.PhenotypeEffectPlotPanel.java

private BoxAndWhiskerCategoryDataset createDataset() {
    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();

    if (this.showIndividualStrainEffectsCheckBox.isSelected()) {
        for (Entry<String, ? extends Collection<String>> strainGroupEntry : this.strainGroups.entrySet()) {
            for (String strain : strainGroupEntry.getValue()) {
                dataset.add(this.phenotypeData.get(strain), strain, strainGroupEntry.getKey());
            }//from w  w w .j ava  2s .c  o m
        }
    } else {
        Map<String, Double> meanPhenoData = new HashMap<String, Double>(this.phenotypeData.size());
        for (Entry<String, List<Double>> phenoEntry : this.phenotypeData.entrySet()) {
            if (!phenoEntry.getValue().isEmpty()) {
                double sum = 0.0;
                for (double value : phenoEntry.getValue()) {
                    sum += value;
                }
                double mean = sum / phenoEntry.getValue().size();

                meanPhenoData.put(phenoEntry.getKey(), mean);
            }
        }

        for (Entry<String, ? extends Collection<String>> strainGroupEntry : this.strainGroups.entrySet()) {
            List<Double> valueList = new ArrayList<Double>(strainGroupEntry.getValue().size());
            for (String strain : strainGroupEntry.getValue()) {
                valueList.add(meanPhenoData.get(strain));
            }
            dataset.add(valueList, SequenceUtilities.toString(strainGroupEntry.getValue(), ", "),
                    strainGroupEntry.getKey());
        }
    }

    return dataset;
}

From source file:org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDatasetTest.java

/**
 * Confirm that cloning works./*ww  w. ja v a2s.c o m*/
 */
@Test
public void testCloning() throws CloneNotSupportedException {
    DefaultBoxAndWhiskerCategoryDataset d1 = new DefaultBoxAndWhiskerCategoryDataset();
    d1.add(new BoxAndWhiskerItem(new Double(1.0), new Double(2.0), new Double(3.0), new Double(4.0),
            new Double(5.0), new Double(6.0), new Double(7.0), new Double(8.0), new ArrayList()), "ROW1",
            "COLUMN1");
    DefaultBoxAndWhiskerCategoryDataset d2 = (DefaultBoxAndWhiskerCategoryDataset) d1.clone();
    assertTrue(d1 != d2);
    assertTrue(d1.getClass() == d2.getClass());
    assertTrue(d1.equals(d2));

    // test independence
    d1.add(new BoxAndWhiskerItem(new Double(1.0), new Double(2.0), new Double(3.0), new Double(4.0),
            new Double(5.0), new Double(6.0), new Double(7.0), new Double(8.0), new ArrayList()), "ROW2",
            "COLUMN1");
    assertFalse(d1.equals(d2));
}

From source file:smellminer.engine.JFreeChartDemo.java

/**
 * Creates a sample dataset.//from   w  ww . j  av  a  2 s  . co  m
 * 
 * @return A sample dataset.
 */
public DefaultBoxAndWhiskerCategoryDataset createSampleDataset() {

    final int seriesCount = 3;
    final int categoryCount = 4;
    final int entityCount = 22;

    final DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();
    for (int i = 0; i < seriesCount; i++) {
        for (int j = 0; j < categoryCount; j++) {
            final List list = new ArrayList();
            // add some values...
            for (int k = 0; k < entityCount; k++) {
                final double value1 = 10.0 + Math.random() * 3;
                list.add(new Double(value1));
                final double value2 = 11.25 + Math.random(); // concentrate values in the middle
                list.add(new Double(value2));
            }
            LOGGER.debug("Adding series " + i);
            LOGGER.debug(list.toString());
            dataset.add(list, "Series " + i, " Type " + j);
        }

    }

    return dataset;
}

From source file:org.jfree.chart.demo.BoxAndWhiskerDemo.java

/**
 * Creates a sample dataset./* ww w. j av  a2 s.  c  o  m*/
 * 
 * @return A sample dataset.
 */
private BoxAndWhiskerCategoryDataset createSampleDataset() {

    final int seriesCount = 3;
    final int categoryCount = 4;
    final int entityCount = 22;

    final DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();
    for (int i = 0; i < seriesCount; i++) {
        for (int j = 0; j < categoryCount; j++) {
            final List list = new ArrayList();
            // add some values...
            for (int k = 0; k < entityCount; k++) {
                final double value1 = 10.0 + Math.random() * 3;
                list.add(new Double(value1));
                final double value2 = 11.25 + Math.random(); // concentrate values in the middle
                list.add(new Double(value2));
            }
            LOGGER.debug("Adding series " + i);
            LOGGER.debug(list.toString());
            dataset.add(list, "Series " + i, " Type " + j);
        }

    }

    return dataset;
}

From source file:sim.util.media.chart.BoxPlotGenerator.java

protected void buildChart() {
    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();

    // we build the chart manually rather than using ChartFactory
    // because we need to customize the getDataRange method below

    CategoryAxis categoryAxis = new CategoryAxis("");
    NumberAxis valueAxis = new NumberAxis("Untitled Y Axis");
    valueAxis.setAutoRangeIncludesZero(false);
    BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer) {
        // Customizing this method in order to provide a bit of
        // vertical buffer.  Otherwise the bar chart box gets drawn
        // slightly off-chart, which looks really bad.

        public Range getDataRange(ValueAxis axis) {
            Range range = super.getDataRange(axis);
            if (range == null)
                return null;
            final double EXTRA_PERCENTAGE = 0.02;
            return Range.expand(range, EXTRA_PERCENTAGE, EXTRA_PERCENTAGE);
        }// www .j  a  v a2  s  . com
    };

    chart = new JFreeChart("Untitled Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    ChartFactory.getChartTheme().apply(chart);

    chart.setAntiAlias(true);
    chartPanel = buildChartPanel(chart);
    setChartPanel(chartPanel);

    // this must come last because the chart must exist for us to set its dataset
    setSeriesDataset(dataset);
}