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.ispy.ui.graphing.chart.plot.ISPYCategoricalCorrelationPlot.java

private DefaultBoxAndWhiskerCategoryDataset createChartData() {

    DefaultBoxAndWhiskerCategoryDataset dataSet = new DefaultBoxAndWhiskerCategoryDataset();

    int i = 0;//from  ww w  . ja v  a 2 s .c o m
    ReporterInfo ri;
    String sequenceName = "";
    for (DataPointVector vec : categoryData) {
        if ((reporterInfoList != null) && (!reporterInfoList.isEmpty())) {
            ri = reporterInfoList.get(i);
            if (ri != null) {
                sequenceName = ri.getGeneSymbol() + " " + ri.getReporterName();
            }
        }
        //only using the X component of the vector to hold the data y and z are not used.
        List<Double> values = removeNaNandNulls(vec.getXValues());
        String categoryName = vec.getName() + " N=" + values.size();
        dataSet.add(values, sequenceName, categoryName);

    }
    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  w  ww . ja  v  a 2  s . com*/
        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:net.sf.maltcms.chromaui.normalization.spi.charts.PeakGroupRtBoxPlot.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>());
        }/*w  w w  .j a va 2 s  . c o 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);
        NumberAxis yAxis = new NumberAxis("Peak Apex Retention Time");
        yAxis.setAutoRange(true);
        yAxis.setAutoRangeIncludesZero(false);
        CategoryPlot cp = new CategoryPlot(baw, new CategoryAxis("Treatment Groups"), yAxis, 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:edu.gmu.cs.sim.util.media.chart.BoxPlotGenerator.java

protected void update() {
    // We have to rebuild the dataset from scratch (deleting and replacing it) because JFreeChart's
    // BoxPlot facility doesn't have a way to remove or move elements.  Stupid stupid stupid.

    SeriesAttributes[] sa = getSeriesAttributes();
    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();

    for (int i = 0; i < sa.length; i++) {
        BoxPlotSeriesAttributes attributes = (BoxPlotSeriesAttributes) (sa[i]);
        double[][] values = attributes.getValues();
        String[] labels = attributes.getLabels();
        //UniqueString series = new UniqueString(attributes.getSeriesName());
        String series = attributes.getSeriesName();
        for (int j = 0; j < values.length; j++) {
            dataset.add(buildList(values[j]), series, labels[j]);
        }/*from   w w  w  .j  av a2s. c  o  m*/
    }

    ((BoxAndWhiskerRenderer) (((CategoryPlot) (chart.getPlot())).getRenderer()))
            .setMaximumBarWidth(getMaximumWidth());

    setSeriesDataset(dataset);
}

From source file:org.matsim.counts.algorithms.graphs.BoxPlotErrorGraph.java

@SuppressWarnings("unchecked")
@Override/*w  ww .  j  a  v a  2s. c o  m*/
public JFreeChart createChart(final int nbr) {

    DefaultBoxAndWhiskerCategoryDataset dataset0 = new DefaultBoxAndWhiskerCategoryDataset();
    DefaultBoxAndWhiskerCategoryDataset dataset1 = new DefaultBoxAndWhiskerCategoryDataset();

    final ArrayList<Double>[] listRel = new ArrayList[24];
    final ArrayList<Double>[] listAbs = new ArrayList[24];

    // init
    for (int i = 0; i < 24; i++) {
        listRel[i] = new ArrayList<Double>();
        listAbs[i] = new ArrayList<Double>();
    }

    // add the values of all counting stations to each hour
    for (CountSimComparison cc : this.ccl_) {
        int hour = cc.getHour() - 1;
        listRel[hour].add(cc.calculateRelativeError());
        listAbs[hour].add(cc.getSimulationValue() - cc.getCountValue());
    }

    // add the collected values to the graph / dataset
    for (int i = 0; i < 24; i++) {
        dataset0.add(listRel[i], "Rel Error", Integer.toString(i + 1));
        dataset1.add(listAbs[i], "Abs Error", Integer.toString(i + 1));
    }

    String title = "Iteration: " + this.iteration_;

    final CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot();

    final CategoryAxis xAxis = new CategoryAxis("Hour");
    final NumberAxis yAxis0 = new NumberAxis("Signed Rel. Error [%]");
    final NumberAxis yAxis1 = new NumberAxis("Signed Abs. Error [veh]");
    yAxis0.setAutoRangeIncludesZero(false);
    yAxis1.setAutoRangeIncludesZero(false);

    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setSeriesToolTipGenerator(0, new BoxAndWhiskerToolTipGenerator());

    CategoryPlot subplot0 = new CategoryPlot(dataset0, xAxis, yAxis0, renderer);
    CategoryPlot subplot1 = new CategoryPlot(dataset1, xAxis, yAxis1, renderer);

    plot.add(subplot0);
    plot.add(subplot1);

    final CategoryAxis axis1 = new CategoryAxis("hour");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    axis1.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    plot.setDomainAxis(axis1);

    this.chart_ = new JFreeChart(title, new Font("SansSerif", Font.BOLD, 14), plot, false);
    return this.chart_;
}

From source file:org.matsim.counts.algorithms.graphs.BoxPlotNormalizedErrorGraph.java

@SuppressWarnings("unchecked")
@Override//from  w  ww. ja va2 s . com
public JFreeChart createChart(final int nbr) {

    DefaultBoxAndWhiskerCategoryDataset dataset0 = new DefaultBoxAndWhiskerCategoryDataset();
    DefaultBoxAndWhiskerCategoryDataset dataset1 = new DefaultBoxAndWhiskerCategoryDataset();

    final ArrayList<Double>[] listRel = new ArrayList[24];
    final ArrayList<Double>[] listAbs = new ArrayList[24];

    // init
    for (int i = 0; i < 24; i++) {
        listRel[i] = new ArrayList<Double>();
        listAbs[i] = new ArrayList<Double>();
    }

    // add the values of all counting stations to each hour
    for (CountSimComparison cc : this.ccl_) {
        int hour = cc.getHour() - 1;
        listRel[hour].add(cc.calculateNormalizedRelativeError() * 100);
        listAbs[hour].add(cc.getSimulationValue() - cc.getCountValue());
    }

    // add the collected values to the graph / dataset
    for (int i = 0; i < 24; i++) {
        dataset0.add(listRel[i], "Rel Norm Error", Integer.toString(i + 1));
        dataset1.add(listAbs[i], "Abs Error", Integer.toString(i + 1));
    }

    String title = "Iteration: " + this.iteration_;

    final CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot();

    final CategoryAxis xAxis = new CategoryAxis("Hour");
    final NumberAxis yAxis0 = new NumberAxis("Norm. Rel. Error [%]");
    final NumberAxis yAxis1 = new NumberAxis("Signed Abs. Error [veh]");
    yAxis0.setAutoRangeIncludesZero(false);
    yAxis1.setAutoRangeIncludesZero(false);

    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setSeriesToolTipGenerator(0, new BoxAndWhiskerToolTipGenerator());

    CategoryPlot subplot0 = new CategoryPlot(dataset0, xAxis, yAxis0, renderer);
    CategoryPlot subplot1 = new CategoryPlot(dataset1, xAxis, yAxis1, renderer);

    plot.add(subplot0);
    plot.add(subplot1);

    final CategoryAxis axis1 = new CategoryAxis("hour");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    axis1.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    plot.setDomainAxis(axis1);

    this.chart_ = new JFreeChart(title, new Font("SansSerif", Font.BOLD, 14), plot, false);
    return this.chart_;
}

From source file:edu.ucla.stat.SOCR.analyses.gui.Chart.java

private BoxAndWhiskerCategoryDataset createBoxAndWhiskerDataset(int seriesCount, int categoryCount,
        String[] seriesName, String[][] categoryName, double[][][] values) {

    List<Double> list;

    DefaultBoxAndWhiskerCategoryDataset result = new DefaultBoxAndWhiskerCategoryDataset();

    for (int s = 0; s < seriesCount; s++) {
        for (int c = 0; c < categoryCount; c++) {
            list = new java.util.ArrayList<Double>();
            for (int i = 0; i < Array.getLength(values[s][c]); i++)
                list.add(new Double(values[s][c][i]));
            result.add(list, seriesName[s], categoryName[s][c]);
        }// w  ww  .  jav a  2  s  .c  om
    }
    return result;

}

From source file:guineu.modules.visualization.intensityboxplot.IntensityBoxPlotFrame.java

private BoxAndWhiskerCategoryDataset createSampleDataset() {

    final DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();

    final List list = new ArrayList();
    if (!xAxisValueSource.equals("Sample")) {
        Dataset data = GuineuCore.getDesktop().getSelectedDataFiles()[0];
        List<String> parameterValues = data.getParameterAvailableValues((String) xAxisValueSource);
        for (int i = 0; i < parameterValues.size(); i++) {
            for (String sampleName : this.selectedFiles) {
                if (parameterValues.get(i)
                        .equals(data.getParametersValue(sampleName, (String) xAxisValueSource))) {
                    for (int k = 0; k < this.selectedRows.length; k++) {
                        Double value = (Double) this.selectedRows[k].getPeak(sampleName);
                        list.add(value);

                    }/*ww  w  .  j ava2  s. c o m*/
                }
            }

            dataset.add(BoxAndWhiskerCalculator.calculateBoxAndWhiskerStatistics(list), "Series ",
                    parameterValues.get(i));
        }
    } else {
        for (int i = 0; i < this.selectedFiles.length; i++) {
            for (int k = 0; k < this.selectedRows.length; k++) {
                Double value = (Double) this.selectedRows[k].getPeak(this.selectedFiles[i]);
                list.add(value);
            }
            dataset.add(BoxAndWhiskerCalculator.calculateBoxAndWhiskerStatistics(list), "Series ",
                    this.selectedFiles[i]);
        }
    }

    return dataset;
}

From source file:edu.ucla.stat.SOCR.analyses.gui.Chart.java

public JFreeChart getBoxAndWhiskerChart(String title, String xLabel, String yLabel, int sCount, int cCount,
        int xyLength, String[][] input) {

    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();
    for (int s = 0; s < sCount; s++)
        for (int c = 0; c < cCount; c++) {
            String v = "";
            for (int i = 0; i < xyLength; i++)
                if (input[i][s] != null && input[i][s].length() != 0)
                    v = v + input[i][s] + ",";

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

        }/*from   w  w  w  . jav a  2 s  .c  o  m*/

    JFreeChart chart = createBoxAndWhiskerChart(title, xLabel, yLabel, dataset);
    return chart;

}

From source file:keel.Algorithms.UnsupervisedLearning.AssociationRules.Visualization.keelassotiationrulesboxplot.ResultsProccessor.java

public void writeToFile(String outName)
        throws FileNotFoundException, UnsupportedEncodingException, IOException {
    //calcMeans();

    // Create JFreeChart Dataset
    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();

    HashMap<String, ArrayList<Double>> measuresFirst = algorithmMeasures.entrySet().iterator().next()
            .getValue();//from w w w  .  ja  v a  2s. c  o  m
    for (Map.Entry<String, ArrayList<Double>> measure : measuresFirst.entrySet()) {
        String measureName = measure.getKey();
        //Double measureValue = measure.getValue();
        dataset.clear();

        for (Map.Entry<String, HashMap<String, ArrayList<Double>>> entry : algorithmMeasures.entrySet()) {
            String alg = entry.getKey();
            ArrayList<Double> measureValues = entry.getValue().get(measureName);

            // Parse algorithm name to show it correctly
            String aName = alg.substring(0, alg.length() - 1);
            int startAlgName = aName.lastIndexOf("/");
            aName = aName.substring(startAlgName + 1);

            dataset.add(measureValues, aName, measureName);
        }

        // Tutorial: http://www.java2s.com/Code/Java/Chart/JFreeChartBoxAndWhiskerDemo.htm
        final CategoryAxis xAxis = new CategoryAxis("Algorithm");
        final NumberAxis yAxis = new NumberAxis("Value");
        yAxis.setAutoRangeIncludesZero(false);
        final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();

        // Black and White
        int numItems = algorithmMeasures.size();
        for (int i = 0; i < numItems; i++) {
            Color color = Color.DARK_GRAY;
            if (i % 2 == 1) {
                color = Color.LIGHT_GRAY;
            }
            renderer.setSeriesPaint(i, color);
            renderer.setSeriesOutlinePaint(i, Color.BLACK);
        }

        renderer.setMeanVisible(false);
        renderer.setFillBox(false);
        renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
        final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

        Font font = new Font("SansSerif", Font.BOLD, 10);
        //ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
        JFreeChart jchart = new JFreeChart("Assotiation Rules Measures - BoxPlot", font, plot, true);
        //StandardChartTheme.createLegacyTheme().apply(jchart);

        int width = 640 * 2; /* Width of the image */
        int height = 480 * 2; /* Height of the image */

        // JPEG
        File chart = new File(outName + "_" + measureName + "_boxplot.jpg");
        ChartUtilities.saveChartAsJPEG(chart, jchart, width, height);

        // SVG
        SVGGraphics2D g2 = new SVGGraphics2D(width, height);
        Rectangle r = new Rectangle(0, 0, width, height);
        jchart.draw(g2, r);
        File BarChartSVG = new File(outName + "_" + measureName + "_boxplot.svg");
        SVGUtils.writeToSVG(BarChartSVG, g2.getSVGElement());
    }

}