Example usage for org.jfree.data.statistics SimpleHistogramDataset addObservation

List of usage examples for org.jfree.data.statistics SimpleHistogramDataset addObservation

Introduction

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

Prototype

public void addObservation(double value) 

Source Link

Document

Adds an observation to the dataset (by incrementing the item count for the appropriate bin).

Usage

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

/**
 * Some checks for the removeAllBins() method.
 *///from w  w w .  j av  a  2  s  . c  om
@Test
public void testRemoveAllBins() {
    SimpleHistogramDataset d1 = new SimpleHistogramDataset("D1");
    d1.addBin(new SimpleHistogramBin(0.0, 1.0));
    d1.addObservation(0.5);
    d1.addBin(new SimpleHistogramBin(2.0, 3.0));
    assertEquals(2, d1.getItemCount(0));
    d1.removeAllBins();
    assertEquals(0, d1.getItemCount(0));
}

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

/**
 * Some checks for the clearObservations() method.
 *///from   w w  w.  j  a  va  2s . c om
@Test
public void testClearObservations() {
    SimpleHistogramDataset d1 = new SimpleHistogramDataset("D1");
    d1.clearObservations();
    assertEquals(0, d1.getItemCount(0));
    d1.addBin(new SimpleHistogramBin(0.0, 1.0));
    d1.addObservation(0.5);
    assertEquals(1.0, d1.getYValue(0, 0), EPSILON);
}

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

/**
 * Some checks for the clone() method.//w w  w.  j av  a  2s . com
 */
@Test
public void testCloning() throws CloneNotSupportedException {
    SimpleHistogramDataset d1 = new SimpleHistogramDataset("Dataset 1");
    SimpleHistogramDataset d2 = (SimpleHistogramDataset) d1.clone();
    assertTrue(d1 != d2);
    assertTrue(d1.getClass() == d2.getClass());
    assertTrue(d1.equals(d2));

    // check that clone is independent of the original
    d2.addBin(new SimpleHistogramBin(2.0, 3.0));
    d2.addObservation(2.3);
    assertFalse(d1.equals(d2));
}

From source file:info.financialecology.finance.utilities.datastruct.VersatileChart.java

public JFreeChart drawSimpleHistogram(String name, ArrayList<VersatileTimeSeries> atsArray) {
    JFreeChart chart;//from   w w w . j a  v a2 s. c  o m
    int count = 0;
    double min = 0, max = 0, tmpMin, tmpMax;

    for (VersatileTimeSeries ats : atsArray) {
        if (count == 0) {
            min = ats.getMinY();
            max = ats.getMaxY();
        } else {
            tmpMin = ats.getMinY();
            tmpMax = ats.getMaxY();
            min = tmpMin < min ? tmpMin : min;
            max = tmpMax > max ? tmpMax : max;
        }
    }

    max = max > 0 ? max * 1.05 : max / 1.05;
    min = min > 0 ? min / 1.05 : min * 1.05;

    SimpleHistogramDataset dataSet = new SimpleHistogramDataset(name);

    for (int i = 0; i < params.numBins; i++) {
        double start = min + i * ((max - min) / params.numBins);
        double end = start + ((max - min) / params.numBins) * 0.999999999999;

        SimpleHistogramBin histBin = new SimpleHistogramBin(start, end, true, true);
        dataSet.addBin(histBin);
    }

    for (VersatileTimeSeries ats : atsArray) {
        for (int i = 0; i < ats.getItemCount(); i++) {
            double value = ats.getValue(i).doubleValue();

            try {
                dataSet.addObservation(ats.getValue(i).doubleValue());
            } catch (Throwable t) {
                // sometimes this throws an exception when the value falls within the narrow gaps of the bins
            }
        }
    }
    chart = ChartFactory.createHistogram(params.title, params.xLabel, params.yLabel, dataSet,
            PlotOrientation.VERTICAL, params.legend, params.toolTips, false);

    return chart;
}