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

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

Introduction

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

Prototype

public void add(BoxAndWhiskerItem item, Comparable rowKey, Comparable columnKey) 

Source Link

Document

Adds a list of values relating to one Box and Whisker entity to the table.

Usage

From source file:gov.nih.nci.cma.web.graphing.GEPlot.java

public String generateBWLog2IntensityChart(String xAxisLabel, String yAxisLabel, HttpSession session,
        PrintWriter pw, boolean isCoinPlot) {
    String bwFilename = "";

    //PlotSize ps = PlotSize.MEDIUM;

    JFreeChart bwChart = null;//from   ww w .j  a v  a  2 s .com
    try {
        //IMAGE Size Control

        CategoryAxis xAxis = new CategoryAxis(xAxisLabel);
        xAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
        NumberAxis yAxis = new NumberAxis(yAxisLabel);
        yAxis.setAutoRangeIncludesZero(true);
        BoxAndWhiskerCoinPlotRenderer bwRenderer = null;
        CategoryPlot bwPlot = null;

        if (isCoinPlot) {
            Map<String, List<Double>> groupMap = rawDataMap.get(reporterName);
            DefaultBoxAndWhiskerCategoryDataset smallBwdataset = new DefaultBoxAndWhiskerCategoryDataset();
            int row = 0;
            int column = 0;
            HashMap<String, List> caIntegatorCoinList = new HashMap<String, List>();
            for (String group : groupList) {
                smallBwdataset.add(groupMap.get(group), reporterName, group);
                caIntegatorCoinList.put(row + "_" + column++, groupMap.get(group));
            }
            bwRenderer = new BoxAndWhiskerCoinPlotRenderer(caIntegatorCoinList);
            bwRenderer.setDisplayAllOutliers(true);
            bwRenderer.setDisplayCoinCloud(true);
            bwRenderer.setDisplayMean(false);
            bwRenderer.setFillBox(false);
            bwRenderer.setPlotColor(null);
            bwPlot = new CategoryPlot(smallBwdataset, xAxis, yAxis, bwRenderer);

            if (groupList.size() < 6)
                imgW = 200;

        } else {
            bwRenderer = new BoxAndWhiskerCoinPlotRenderer();
            bwRenderer.setDisplayAllOutliers(true);
            bwRenderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() {
                public String generateToolTip(CategoryDataset dataset, int series, int item) {
                    String tt = "";
                    NumberFormat formatter = new DecimalFormat(".####");
                    String key = "";
                    //String s = formatter.format(-1234.567);  // -001235
                    if (dataset instanceof DefaultBoxAndWhiskerCategoryDataset) {
                        DefaultBoxAndWhiskerCategoryDataset ds = (DefaultBoxAndWhiskerCategoryDataset) dataset;
                        try {
                            String med = formatter.format(ds.getMedianValue(series, item));
                            tt += "Median: " + med + "<br/>";
                            tt += "Mean: " + formatter.format(ds.getMeanValue(series, item)) + "<br/>";
                            tt += "Q1: " + formatter.format(ds.getQ1Value(series, item)) + "<br/>";
                            tt += "Q3: " + formatter.format(ds.getQ3Value(series, item)) + "<br/>";
                            tt += "Max: " + formatter.format(
                                    FaroutOutlierBoxAndWhiskerCalculator.getMaxFaroutOutlier(ds, series, item))
                                    + "<br/>";
                            tt += "Min: " + formatter.format(
                                    FaroutOutlierBoxAndWhiskerCalculator.getMinFaroutOutlier(ds, series, item))
                                    + "<br/>";
                            tt += "<br/><br/>Please click on the box and whisker to view a plot for this reporter.<br/>";
                            key = ds.getRowKeys().get(series).toString();
                        } catch (Exception e) {
                        }
                    }
                    String returnString = "onclick=\"popCoin('" + geneSymbol + "','" + key + "');\" | ";

                    return returnString + tt;
                }
            });
            bwRenderer.setFillBox(false);
            bwPlot = new CategoryPlot(bwdataset, xAxis, yAxis, bwRenderer);
        }

        bwChart = new JFreeChart(bwPlot);

        bwChart.setBackgroundPaint(java.awt.Color.white);
        LegendTitle title = bwChart.getLegend();
        LegendItemSource[] sources = title.getSources();

        legendItemCollection = sources[0].getLegendItems();
        bwChart.removeLegend();

        // Write the chart image to the temporary directory
        ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());

        // BW
        if (bwChart != null) {
            //int bwwidth = new BigDecimal(1.5).multiply(new BigDecimal(imgW)).intValue();
            bwFilename = ServletUtilities.saveChartAsPNG(bwChart, imgW, 400, info, session);
            CustomOverlibToolTipTagFragmentGenerator ttip = new CustomOverlibToolTipTagFragmentGenerator();
            ttip.setExtra(" href='javascript:void(0);' "); //must have href for area tags to have cursor:pointer
            ChartUtilities.writeImageMap(pw, bwFilename, info, ttip, new StandardURLTagFragmentGenerator());
            info.clear(); // lose the first one
            info = new ChartRenderingInfo(new StandardEntityCollection());
        }
        //END  BW

        pw.flush();

    } catch (Exception e) {
        System.out.println("Exception - " + e.toString());
        e.printStackTrace(System.out);
    }
    // return filename;
    //charts.put("errorBars", log2Filename);
    //charts.put("noErrorBars", rawFilename);
    //charts.put("bwFilename", bwFilename);
    //charts.put("legend", legendHtml);
    //charts.put("size", ps.toString());

    return bwFilename;
}

From source file:smellminer.engine.JFreeChartDemo.java

/**
 * Creates a sample dataset.//from w ww . j  a  v  a 2  s  .c  om
 * 
 * @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.//from w w  w .ja va  2s  .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:edu.ucla.stat.SOCR.chart.SuperBoxAndWhiskerChart_Vertical.java

/**
 * /*w w  w . ja v  a 2s.c o  m*/
 * @param isDemo data come from demo(true) or dataTable(false)
 * @return
 */
protected BoxAndWhiskerCategoryDataset createDataset(boolean isDemo) {

    if (isDemo) {
        SERIES_COUNT = 3;
        // CATEGORY_COUNT = 5;
        VALUE_COUNT = 20;

        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 {

        setArrayFromTable();

        String[][] x = new String[xyLength][dependentVarLength];
        String[][] y = new String[xyLength][independentVarLength];

        for (int index = 0; index < dependentVarLength; index++)
            for (int i = 0; i < xyLength; i++)
                x[i][index] = depValues[i][index];

        // create the dataset... 
        DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();
        SERIES_COUNT = dependentVarLength;
        //CATEGORY_COUNT = independentVarLength;

        values_storage = new String[SERIES_COUNT][CATEGORY_COUNT];

        for (int s = 0; s < SERIES_COUNT; s++)
            for (int c = 0; c < CATEGORY_COUNT; c++) {
                String v = "";
                for (int i = 0; i < xyLength; i++)
                    if (x[i][s] != null && x[i][s].length() != 0)
                        v = v + x[i][s] + ",";

                values_storage[s][c] = v;
                dataset.add(createValueList(v), dependentHeaders[s], "Category " + c);

            }

        return dataset;
    }
}

From source file:de.hs.mannheim.modUro.reader.BoxAndWhiskersPlotDiagram.java

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

    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();

    List<String> sortedModels = bwpModel.getModelTypeName();
    sortedModels.sort(String::compareTo);
    for (String model : sortedModels) {
        StatisticValues stat = bwpModel.getStatisticValues().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:
        int n = stat.size();
        dataset.add(item, "", model + " (n=" + n + ")");
    }
    return dataset;
}

From source file:adapters.BoxSeriesCollectionAdapter.java

/**
 * Modified Method: change label from serie to Cluster plus the number of instances in the cluster
 *
 * Creates a new <TT>BoxSeriesCollection</TT> instance with default
 *    parameters and given data series. The input parameter represents series
 *    of point sets.//from   w  w  w.  ja v a 2  s  .  c  o m
 *
 * @param data series of point sets.
 *
 *
 */
public BoxSeriesCollectionAdapter(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]);

        // "i + 1" since the cluster label should start with 1 instead of 0
        tempSeriesCollection.add(list, 0, "[ " + data[i].length + " ]");
        list.clear();
    }
    ((BoxAndWhiskerRenderer) renderer).setMaximumBarWidth(BARWIDTH);
}

From source file:edu.ucla.stat.SOCR.chart.SuperBoxAndWhiskerChart.java

/**
 * //ww  w .j a v a 2  s.c o m
 * @param isDemo data come from demo(true) or dataTable(false)
 * @return
 */
protected BoxAndWhiskerCategoryDataset createDataset(boolean isDemo) {

    if (isDemo) {
        SERIES_COUNT = 3;
        CATEGORY_COUNT = 5;
        VALUE_COUNT = 20;

        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 {
        trimColumn = true;
        setArrayFromTable();

        String[][] x = new String[xyLength][independentVarLength];
        String[][] y = new String[xyLength][dependentVarLength];

        for (int index = 0; index < independentVarLength; index++)
            for (int i = 0; i < xyLength; i++)
                x[i][index] = indepValues[i][index];

        SERIES_COUNT = 0;
        for (int index = 0; index < dependentVarLength; index++)
            for (int i = 0; i < xyLength; i++) {
                if (depValues[i][index] != null) {
                    y[i][index] = depValues[i][index];
                    SERIES_COUNT++;
                }
            }

        // create the dataset... 
        DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();

        CATEGORY_COUNT = independentVarLength;

        values_storage = new String[SERIES_COUNT][CATEGORY_COUNT];

        for (int s = 0; s < SERIES_COUNT; s++)
            for (int c = 0; c < CATEGORY_COUNT; c++) {
                if (x[s][c] == null || x[s][c].length() == 0) {
                    x[s][c] = "0.0, 0.0";
                }
                if (y[s][0] != null) {
                    dataset.add(createValueList(x[s][c]), y[s][0], independentHeaders[c]);
                    values_storage[s][c] = x[s][c];
                }

            }

        return dataset;
    }
}

From source file:playground.christoph.evacuation.analysis.EvacuationTimePictureWriter.java

private JFreeChart createBoxplotChart(List<Double> travelTimes) {

    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();
    dataset.add(travelTimes, "Series", "");

    JFreeChart chart = ChartFactory.createBoxAndWhiskerChart(null, null, "evacuation travel time", dataset,
            false);//from   w w w. jav a 2  s.co  m
    chart.getCategoryPlot().setForegroundAlpha(0.75f);
    return chart;
}

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.SingleCellAnalysisController.java

/**
 * Generate the dataset for the box plot with the track speeds.
 *
 * @return a DefaultBoxAndWhiskerCategoryDataset
 */// www.  jav  a  2  s  .c o  m
private DefaultBoxAndWhiskerCategoryDataset getSpeedBoxPlotDataset() {
    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();
    singleCellMainController.getFilteringMap().keySet().stream().forEach((singleCellConditionDataHolder) -> {
        dataset.add(Arrays.asList(singleCellConditionDataHolder.getTrackSpeedsVector()),
                singleCellConditionDataHolder.getPlateCondition().toString(), "");
    });
    return dataset;
}

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.SingleCellAnalysisController.java

/**
 * Generate the dataset for the box plot with the track directionality
 * values.//w  w w  . jav a2  s  .c o  m
 *
 * @return a DefaultBoxAndWhiskerCategoryDataset
 */
private DefaultBoxAndWhiskerCategoryDataset getDirecBoxPlotDataset() {
    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();
    singleCellMainController.getFilteringMap().keySet().stream().forEach((singleCellConditionDataHolder) -> {
        dataset.add(Arrays.asList(singleCellConditionDataHolder.getEndPointDirectionalityRatios()),
                singleCellConditionDataHolder.getPlateCondition().toString(), "");
    });
    return dataset;
}