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:org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDatasetTest.java

/**
 * Confirm that cloning works./*from  w  ww . j av  a2  s .  co  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:org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDatasetTest.java

/**
 * Some checks for the getRangeBounds() method.
 */// ww w  .j  ava  2 s.  c  om
@Test
public void testGetRangeBounds() {
    DefaultBoxAndWhiskerCategoryDataset d1 = new DefaultBoxAndWhiskerCategoryDataset();
    d1.add(new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList()), "R1", "C1");
    assertEquals(new Range(7.0, 8.0), d1.getRangeBounds(false));
    assertEquals(new Range(7.0, 8.0), d1.getRangeBounds(true));

    d1.add(new BoxAndWhiskerItem(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, new ArrayList()), "R1", "C1");
    assertEquals(new Range(7.5, 8.5), d1.getRangeBounds(false));
    assertEquals(new Range(7.5, 8.5), d1.getRangeBounds(true));

    d1.add(new BoxAndWhiskerItem(2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, new ArrayList()), "R2", "C1");
    assertEquals(new Range(7.5, 9.5), d1.getRangeBounds(false));
    assertEquals(new Range(7.5, 9.5), d1.getRangeBounds(true));

    // this replaces the entry with the current minimum value, but the new
    // minimum value is now in a different item
    d1.add(new BoxAndWhiskerItem(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 8.6, 9.6, new ArrayList()), "R1", "C1");
    assertEquals(new Range(8.5, 9.6), d1.getRangeBounds(false));
    assertEquals(new Range(8.5, 9.6), d1.getRangeBounds(true));
}

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

/**
 * A simple test for bug report 1701822.
 *///w  ww.  j  a  va  2 s  .  c  om
@Test
public void test1701822() {
    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();
    try {
        dataset.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), null, new Double(8.0), new ArrayList()),
                "ROW1", "COLUMN1");
        dataset.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), null, new ArrayList()),
                "ROW1", "COLUMN2");
    } catch (NullPointerException e) {
        assertTrue(false);
    }

}

From source file:gui.TraitViewerDialog.java

@SuppressWarnings("rawtypes")
private ChartPanel getChart(int selectedRow) {

    ArrayList<Float> data = new ArrayList<Float>();
    for (float[] row : tFile.getRows()) {
        if (row[selectedRow + 1] != (float) -99.0) {
            data.add(row[selectedRow + 1]);
        }//from ww w  .  j  a  v  a 2 s. c o  m
    }
    BoxAndWhiskerItem a = BoxAndWhiskerCalculator.calculateBoxAndWhiskerStatistics(data);
    java.util.List l = new ArrayList(0);

    a = new BoxAndWhiskerItem(a.getMean(), a.getMedian(), a.getQ1(), a.getQ3(), a.getMinRegularValue(),
            a.getMaxRegularValue(), a.getMinRegularValue(), a.getMaxRegularValue(), l);
    traitstats.setText(showBoxAndWhiskerItem(a));

    DefaultBoxAndWhiskerCategoryDataset ds2 = new DefaultBoxAndWhiskerCategoryDataset();

    ds2.add(a, (Comparable) 1, (Comparable) 1);
    JFreeChart chart = ChartFactory.createBoxAndWhiskerChart(null, null, null, ds2, false);

    chart.removeLegend();

    // XYPlot plot = chart.getXYPlot();
    CategoryPlot plot = chart.getCategoryPlot();
    plot.getDomainAxis().setVisible(false);
    BoxAndWhiskerRenderer b = (BoxAndWhiskerRenderer) plot.getRenderer();
    // b.setFillBox(false);
    b.setSeriesPaint(0, new Color(236, 55, 169));
    b.setSeriesOutlinePaint(1, new Color(131, 79, 112));
    b.setBaseOutlineStroke(new BasicStroke(1.0f));
    // b.get
    b.setWhiskerWidth(0.8);
    b.setBaseOutlinePaint(new Color(84, 144, 201));
    b.setDefaultEntityRadius(2);
    b.setMaximumBarWidth(0.18);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPopupMenu(null);
    return chartPanel;
}

From source file:playground.anhorni.counts.StdDevBoxPlot.java

public JFreeChart createChart() {
    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();

    ArrayList<Double>[] lists = this.createArrayLists();

    // add the collected values to the graph / dataset
    for (int i = 0; i < 24; i++) {
        dataset.add(lists[i], "hour", Integer.toString(i + 1));
    }/*from w  ww  . j  ava 2 s  .c  o  m*/
    final CategoryAxis xAxis = new CategoryAxis(xlabel);
    xAxis.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 10));
    //xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    final NumberAxis yAxis = new NumberAxis(ylabel);
    yAxis.setAutoRangeIncludesZero(true);

    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setSeriesPaint(0, Color.blue);
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

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

From source file:weka.core.ChartUtils.java

/**
 * Create a box plot from summary data (mean, median, q1, q3, min, max,
 * minOutlier, maxOutlier, list of outliers)
 * /*ww w  .  ja v a2 s.  c  o m*/
 * @param summary summary data
 * @param outliers list of outlier values
 * @param additionalArgs additional options to the renderer
 * @return a box plot chart
 * @throws Exception if a problem occurs
 */
protected static JFreeChart getBoxPlotFromSummaryData(List<Double> summary, List<Double> outliers,
        List<String> additionalArgs) throws Exception {

    if (summary.size() != 8) {
        throw new Exception("Expected 8 values in the summary argument: mean, median, "
                + "q1, q3, min, max, minOutlier, maxOutlier");
    }

    String plotTitle = "Box Plog";
    String userTitle = getOption(additionalArgs, "-title");
    plotTitle = (userTitle != null) ? userTitle : plotTitle;
    String xLabel = getOption(additionalArgs, "-x-label");
    xLabel = xLabel == null ? "" : xLabel;
    String yLabel = getOption(additionalArgs, "-y-label");
    yLabel = yLabel == null ? "" : yLabel;

    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();

    Double mean = summary.get(0);
    Double median = summary.get(1);
    Double q1 = summary.get(2);
    Double q3 = summary.get(3);
    Double min = summary.get(4);
    Double max = summary.get(5);
    Double minOutlier = summary.get(6);
    Double maxOutlier = summary.get(7);

    if (mean.isNaN() || median.isNaN() || min.isNaN() || max.isNaN() || q1.isNaN() || q3.isNaN()) {
        throw new Exception("NaN in summary data - can't generate box plot");
    }

    BoxAndWhiskerItem item = new BoxAndWhiskerItem(mean, median, q1, q3, min, max, minOutlier, maxOutlier,
            outliers);

    dataset.add(item, "", "");

    CategoryAxis xAxis = new CategoryAxis();
    NumberAxis yAxis = new NumberAxis();
    yAxis.setAutoRangeIncludesZero(false);
    BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setMaximumBarWidth(0.15);

    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    JFreeChart chart = new JFreeChart(plotTitle, new Font("SansSerif", Font.BOLD, 12), plot, false);

    return chart;
}

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

/**
 * Some checks for the add() method.//www . j  a  va2  s . co m
 */
@Test
public void testAdd() {
    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();
    BoxAndWhiskerItem item1 = new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList());
    dataset.add(item1, "R1", "C1");

    assertEquals(2.0, dataset.getValue("R1", "C1").doubleValue(), EPSILON);
    assertEquals(1.0, dataset.getMeanValue("R1", "C1").doubleValue(), EPSILON);
    assertEquals(2.0, dataset.getMedianValue("R1", "C1").doubleValue(), EPSILON);
    assertEquals(3.0, dataset.getQ1Value("R1", "C1").doubleValue(), EPSILON);
    assertEquals(4.0, dataset.getQ3Value("R1", "C1").doubleValue(), EPSILON);
    assertEquals(5.0, dataset.getMinRegularValue("R1", "C1").doubleValue(), EPSILON);
    assertEquals(6.0, dataset.getMaxRegularValue("R1", "C1").doubleValue(), EPSILON);
    assertEquals(7.0, dataset.getMinOutlier("R1", "C1").doubleValue(), EPSILON);
    assertEquals(8.0, dataset.getMaxOutlier("R1", "C1").doubleValue(), EPSILON);
    assertEquals(new Range(7.0, 8.0), dataset.getRangeBounds(false));
}

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

/**
 * Some checks for the add() method.//www.j  a  v a2s  .com
 */
@Test
public void testAddUpdatesCachedRange() {
    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();
    BoxAndWhiskerItem item1 = new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList());
    dataset.add(item1, "R1", "C1");

    // now overwrite this item with another
    BoxAndWhiskerItem item2 = new BoxAndWhiskerItem(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, new ArrayList());
    dataset.add(item2, "R1", "C1");

    assertEquals(2.5, dataset.getValue("R1", "C1").doubleValue(), EPSILON);
    assertEquals(1.5, dataset.getMeanValue("R1", "C1").doubleValue(), EPSILON);
    assertEquals(2.5, dataset.getMedianValue("R1", "C1").doubleValue(), EPSILON);
    assertEquals(3.5, dataset.getQ1Value("R1", "C1").doubleValue(), EPSILON);
    assertEquals(4.5, dataset.getQ3Value("R1", "C1").doubleValue(), EPSILON);
    assertEquals(5.5, dataset.getMinRegularValue("R1", "C1").doubleValue(), EPSILON);
    assertEquals(6.5, dataset.getMaxRegularValue("R1", "C1").doubleValue(), EPSILON);
    assertEquals(7.5, dataset.getMinOutlier("R1", "C1").doubleValue(), EPSILON);
    assertEquals(8.5, dataset.getMaxOutlier("R1", "C1").doubleValue(), EPSILON);
    assertEquals(new Range(7.5, 8.5), dataset.getRangeBounds(false));
}

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

protected BoxAndWhiskerCategoryDataset createDataset2(boolean isDemo) {
    if (isDemo) {
        updateStatus("isDemo==true in " + this.getClass().getName()
                + " class! return null Dataset, check the code!");
        return null;
    } else {//from   w  w  w  . ja  v a  2 s. c  o  m

        setArrayFromTable();

        String vs = "";
        row_count = xyLength;
        //System.out.println("row_count="+row_count);
        raw_x = new String[row_count];
        int data_count = 0;
        double[] tmp_xvalue = new double[row_count];

        for (int index = 0; index < independentVarLength; index++)
            for (int i = 0; i < xyLength; i++) {
                raw_x[i] = indepValues[i][index];
                //   System.out.println("raw_x="+raw_x[i]);
                try {

                    // per Ivo request, don't use 0.0 to fill the empty cells 4/16/09
                    if (raw_x[i] == null || raw_x[i].length() == 0) {
                        //   tmp_xvalue[data_count]=0.0;
                        //   vs+="0.0"+",";
                    } else {
                        tmp_xvalue[data_count] = Double.parseDouble(raw_x[i]);
                        vs += raw_x[i] + ",";
                    }
                    data_count++;

                } catch (Exception e) {
                    System.out.println("skipping wrong data " + raw_x[i] + " at " + i);
                }
            }

        //System.out.println("vs="+vs);
        DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();
        dataset.add(createValueList(vs), "", "");
        values_storage[0][0] = vs;
        return dataset;
    }
}

From source file:no.uio.medicine.virsurveillance.charts.BoxAndWhiskerChart_AWT.java

private CategoryDataset createDataset(ArrayList<ArrayList<ArrayList<Float>>> dataPoints,
        ArrayList<ArrayList<String>> categories, ArrayList<String> titles) {
    final int nSeries = 3; //<--n caixes a cada titol equivalent a size de datapoints
    final int nCaixes = 4; //<--titols per caixa. titles. en principi ha de ser igual a dataPoints(x).size
    final int puntsPerCaixa = 22; //<-- dataPoints(i)(j).size()

    final DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();

    int i = 0;/*  w w  w  .  j av  a2s  .  c o  m*/
    for (ArrayList<ArrayList<Float>> boxSet : dataPoints) {
        int j = 0;

        for (ArrayList<Float> box : boxSet) {
            dataset.add(box, titles.get(i), categories.get(i).get(j));
            j++;
        }

        i++;
    }

    return dataset;
}