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

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

Introduction

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

Prototype

public void addObservations(double[] values) 

Source Link

Document

Adds a set of values to the dataset and sends a DatasetChangeEvent to all registered listeners.

Usage

From source file:org.jfree.expdemo.SelectionDemo4.java

/**
 * Creates a sample {@link HistogramDataset}.
 * //from   ww w  . j a va2 s.  c  om
 * @return the dataset.
 */
private static IntervalXYDataset createDataset() {
    SimpleHistogramDataset dataset = new SimpleHistogramDataset("H1");
    double lower = 0.0;
    for (int i = 0; i < 100; i++) {
        double upper = (i + 1) / 10.0;
        SimpleHistogramBin bin = new SimpleHistogramBin(lower, upper, true, false);
        dataset.addBin(bin);
        lower = upper;
    }
    double[] values = new double[1000];
    Random generator = new Random(12345678L);
    for (int i = 0; i < 1000; i++) {
        values[i] = generator.nextGaussian() + 5;
    }
    dataset.addObservations(values);
    return dataset;
}

From source file:ch.zhaw.ias.dito.ui.AnalysisPanel.java

private JFreeChart createHistogramChart(String title, Matrix distanceMatrix) {
    int NUM_OF_BINS = 50;
    SimpleHistogramDataset dataset = new SimpleHistogramDataset("");
    dataset.setAdjustForBinSize(false);/*from   www .j a v  a  2 s . c om*/
    double min = distanceMatrix.extremum(false);
    double max = distanceMatrix.extremum(true);
    double spacing = (max - min) / NUM_OF_BINS;
    double currentBound = min;

    for (int i = 0; i < NUM_OF_BINS - 1; i++) {
        dataset.addBin(new SimpleHistogramBin(currentBound, (currentBound + spacing), true, false));
        currentBound += spacing;
    }
    //ensure that the maximum is included and not lost because of numerical problems
    dataset.addBin(new SimpleHistogramBin(currentBound, max, true, true));
    for (int i = 0; i < distanceMatrix.getColCount(); i++) {
        DVector v = distanceMatrix.col(i);
        dataset.addObservations(v.getValues());
    }
    return ChartFactory.createHistogram(title, Translation.INSTANCE.get("misc.graphic.distance"),
            Translation.INSTANCE.get("misc.graphic.frequency"), dataset, PlotOrientation.VERTICAL, false, true,
            false);
}