Example usage for org.jfree.data.statistics SimpleHistogramBin SimpleHistogramBin

List of usage examples for org.jfree.data.statistics SimpleHistogramBin SimpleHistogramBin

Introduction

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

Prototype

public SimpleHistogramBin(double lowerBound, double upperBound, boolean includeLowerBound,
        boolean includeUpperBound) 

Source Link

Document

Creates a new bin.

Usage

From source file:org.ow2.clif.jenkins.chart.FixedSliceSizeDistributionChart.java

public void addData(double[] values, double min, double max) {
    if (values != null && values.length > 0) {
        double lower = min;
        int sliceSize = this.chartConfiguration.getDistributionSliceSize();
        do {/*from  w ww . ja  va  2 s . c o m*/
            boolean last = (lower + sliceSize >= max);
            this.data.addBin(new SimpleHistogramBin(lower, lower + sliceSize, true, last));
            lower += sliceSize;
        } while (lower < max);

        this.data.setAdjustForBinSize(false);

        this.data.addObservations(values);
    }
}

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

/**
 * Creates a sample {@link HistogramDataset}.
 * /*from   w w w.  j  a va2 s  .  c o m*/
 * @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:imageviewer.tools.HistogramTool.java

public void plot(MouseEvent e) {

    if (e.getSource() instanceof ImagePanel) {
        Image image = ((ImagePanel) e.getSource()).getSource();
        Histogram h = image.getHistogram();
        SimpleHistogramDataset shd = new SimpleHistogramDataset("Voxel distribution");
        for (int i = 0, numBands = h.getNumBands(); i < numBands; i++) {
            int[] binData = h.getBins(i);
            for (int j = 0; j < binData.length; j++) {
                SimpleHistogramBin shb = new SimpleHistogramBin(j - 0.5, j + 0.5, true, false);
                shb.setItemCount(binData[j]);
                shd.addBin(shb);/*ww  w.java  2 s  . c  om*/
            }
        }
        double[] domainBounds = null, rangeBounds = null;
        if (chart != null) {
            ValueAxis va = chart.getXYPlot().getDomainAxis();
            domainBounds = new double[] { va.getLowerBound(), va.getUpperBound() };
            va = chart.getXYPlot().getRangeAxis();
            rangeBounds = new double[] { va.getLowerBound(), va.getUpperBound() };
        }
        chart = ChartFactory.createHistogram(null, "Voxel value", "Count", shd, PlotOrientation.VERTICAL, false,
                true, false);
        chart.setBackgroundPaint(new Color(20, 30, 45));
        chart.setAntiAlias(true);
        ValueAxis domainAxis = chart.getXYPlot().getDomainAxis();
        domainAxis.setLabelFont(axisFont);
        domainAxis.setTickLabelFont(tickFont);
        domainAxis.setAxisLinePaint(Color.white);
        domainAxis.setTickLabelPaint(Color.white);
        domainAxis.setLabelPaint(Color.white);
        if (domainBounds != null) {
            domainAxis.setAutoRange(false);
            domainAxis.setLowerBound(domainBounds[0]);
            domainAxis.setUpperBound(domainBounds[1]);
        } else {
            domainAxis.setLowerBound(0);
        }
        ValueAxis rangeAxis = chart.getXYPlot().getRangeAxis();
        rangeAxis.setLabelFont(axisFont);
        rangeAxis.setTickLabelFont(tickFont);
        rangeAxis.setAxisLinePaint(Color.white);
        rangeAxis.setTickLabelPaint(Color.white);
        rangeAxis.setLabelPaint(Color.white);
        if (rangeBounds != null) {
            rangeAxis.setAutoRange(false);
            rangeAxis.setLowerBound(rangeBounds[0]);
            rangeAxis.setUpperBound(rangeBounds[1]);
        }
        chart.getXYPlot().getRenderer().setSeriesPaint(0, new Color(0, 51, 113));
        ((XYBarRenderer) chart.getXYPlot().getRenderer()).setDrawBarOutline(false);
        chart.getXYPlot().setBackgroundAlpha(0.05f);

        double[] mean = h.getMean();
        double[] sd = h.getStandardDeviation();
        IntervalMarker im = new IntervalMarker(mean[0] - sd[0] / 2, mean[0] + sd[0] / 2);
        im.setPaint(new Color(200, 200, 200, 128));
        chart.getXYPlot().addDomainMarker(0, im, Layer.BACKGROUND);
        cp.setChart(chart);
    }
}

From source file:ch.zhaw.ias.dito.ui.util.SingleHistogramPanel.java

private void switchColumn(int column) {
    chart.setTitle(Translation.INSTANCE.get("misc.graphic.singleHistogramColumn") + " " + column);
    DVector data = m.col(column);//from  w w w .j ava  2 s  .  c o m
    int numOfbins = (int) (data.length() / 20) + 10;

    double min = data.min();
    double max = data.max();
    double spacing = (max - min) / numOfbins;
    double currentBound = min;
    dataset.removeAllBins();
    for (int i = 0; i < numOfbins - 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));

    dataset.clearObservations();
    dataset.addObservations(data.getValues());
    dataset.seriesChanged(null);
}

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

/**
 * Some checks for the clone() method./*from w  ww . ja  v a  2s. c  om*/
 */
@Test
public void testCloning() throws CloneNotSupportedException {
    SimpleHistogramBin b1 = new SimpleHistogramBin(1.1, 2.2, false, true);
    b1.setItemCount(99);
    SimpleHistogramBin b2 = (SimpleHistogramBin) b1.clone();
    assertTrue(b1 != b2);
    assertTrue(b1.getClass() == b2.getClass());
    assertTrue(b1.equals(b2));

    // check that clone is independent of the original
    b2.setItemCount(111);
    assertFalse(b1.equals(b2));
}

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

/**
 * Serialize an instance, restore it, and check for equality.
 *//*from   w ww.  java 2  s  .co m*/
@Test
public void testSerialization() {
    SimpleHistogramBin b1 = new SimpleHistogramBin(1.0, 2.0, false, true);
    b1.setItemCount(123);
    SimpleHistogramBin b2 = (SimpleHistogramBin) TestUtilities.serialised(b1);
    assertEquals(b1, b2);
}

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);//  w  ww .j  a  v a2 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);
}

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

public JFreeChart drawSimpleHistogram(String name, ArrayList<VersatileTimeSeries> atsArray) {
    JFreeChart chart;// w  ww  .  ja va  2s  .  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;
}

From source file:jchrest.gui.Shell.java

private JPanel getHistogramPane(Map<Integer, Integer> contentSizes, String label, String title, String xAxis) {
    int largest = 0;
    for (Integer key : contentSizes.keySet()) {
        if (key > largest)
            largest = key;//from w w w.ja  va  2 s .com
    }
    SimpleHistogramDataset dataset = new SimpleHistogramDataset(label);
    for (int i = 0; i <= largest; ++i) {
        SimpleHistogramBin bin = new SimpleHistogramBin((double) i, (double) (i + 1), true, false);
        int count = 0;
        if (contentSizes.containsKey(i)) {
            count = contentSizes.get(i);
        }
        bin.setItemCount(count);
        dataset.addBin(bin);
    }
    PlotOrientation orientation = PlotOrientation.VERTICAL;
    boolean show = false;
    boolean toolTips = true;
    boolean urls = false;
    JFreeChart chart = ChartFactory.createHistogram(title, xAxis, "frequency", dataset, orientation, show,
            toolTips, urls);

    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(new ChartPanel(chart, 400, 300, 200, 100, 600, 600, true, true, true, true, true, true));
    JButton saveButton = new JButton("Save Data");
    saveButton.setToolTipText("Save the histogram data to a CSV file");
    saveButton.addActionListener(new SaveHistogramActionListener(this, contentSizes));
    panel.add(saveButton, BorderLayout.SOUTH);
    return panel;
}