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

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

Introduction

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

Prototype

public HistogramDataset() 

Source Link

Document

Creates a new (empty) dataset with a default type of HistogramType .FREQUENCY.

Usage

From source file:org.geopublishing.atlasStyler.classification.FeatureClassification.java

@Override
public BufferedImage createHistogramImage(boolean showMean, boolean showSd, int histogramBins,
        String label_xachsis) throws InterruptedException, IOException {
    HistogramDataset hds = new HistogramDataset();
    DoubleArrayList valuesAL;//from   w  w w.j  av a2  s .  c  o m
    valuesAL = getStatistics().elements();
    // new double[] {0.4,3,4,2,5.,22.,4.,2.,33.,12.}
    double[] elements = Arrays.copyOf(valuesAL.elements(), getStatistics().size());
    hds.addSeries(1, elements, histogramBins);

    /** Statically label the Y Axis **/
    String label_yachsis = ASUtil.R("QuantitiesClassificationGUI.Histogram.YAxisLabel");

    JFreeChart chart = org.jfree.chart.ChartFactory.createHistogram(null, label_xachsis, label_yachsis, hds,
            PlotOrientation.VERTICAL, false, true, true);

    /***********************************************************************
     * Paint the classes into the JFreeChart
     */
    int countLimits = 0;
    for (Double cLimit : getClassLimits()) {
        ValueMarker marker = new ValueMarker(cLimit);
        XYPlot plot = chart.getXYPlot();
        marker.setPaint(Color.orange);
        marker.setLabel(String.valueOf(countLimits));
        marker.setLabelAnchor(RectangleAnchor.TOP_LEFT);
        marker.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        plot.addDomainMarker(marker);

        countLimits++;
    }

    /***********************************************************************
     * Optionally painting SD and MEAN into the histogram
     */
    try {
        if (showSd) {
            ValueMarker marker;
            marker = new ValueMarker(getStatistics().standardDeviation(), Color.green.brighter(),
                    new BasicStroke(1.5f));
            XYPlot plot = chart.getXYPlot();
            marker.setLabel(ASUtil.R("QuantitiesClassificationGUI.Histogram.SD.ShortLabel"));
            marker.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT);
            marker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
            plot.addDomainMarker(marker);
        }

        if (showMean) {
            ValueMarker marker;
            marker = new ValueMarker(getStatistics().mean(), Color.green.darker(), new BasicStroke(1.5f));
            XYPlot plot = chart.getXYPlot();
            marker.setLabel(ASUtil.R("QuantitiesClassificationGUI.Histogram.Mean.ShortLabel"));
            marker.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT);
            marker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
            plot.addDomainMarker(marker);
        }

    } catch (Exception e) {
        LOGGER.error("Painting SD and MEAN into the histogram", e);
    }

    /***********************************************************************
     * Render the Chart
     */
    BufferedImage image = chart.createBufferedImage(400, 200);

    return image;
}

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

/**
 * A test for a bug reported in the forum where the series name isn't being
 * returned correctly.//  w  ww .j  a  v  a 2s.  c o  m
 */
@Test
public void testGetSeriesKey() {
    double[] values = { 1.0, 2.0, 3.0, 4.0, 6.0, 12.0, 5.0, 6.3, 4.5 };
    HistogramDataset d1 = new HistogramDataset();
    d1.addSeries("Series 1", values, 5);
    assertEquals("Series 1", d1.getSeriesKey(0));
}

From source file:net.imglib2.script.analysis.Histogram.java

/** Return the JFreeChart with this histogram, and as a side effect, show it in a JFrame
 * that provides the means to edit the dimensions and also the plot properties via a popup menu. */
public JFreeChart asChart(final boolean show) {
    double[] d = new double[this.size()];
    int i = 0;/*  w w  w  .ja  v a  2s  .c om*/
    for (Number num : this.values())
        d[i++] = num.doubleValue();
    HistogramDataset hd = new HistogramDataset();
    hd.setType(HistogramType.RELATIVE_FREQUENCY);
    String title = "Histogram";
    hd.addSeries(title, d, d.length);
    JFreeChart chart = ChartFactory.createHistogram(title, "", "", hd, PlotOrientation.VERTICAL, false, false,
            false);
    setTheme(chart);
    if (show) {
        JFrame frame = new JFrame(title);
        frame.getContentPane().add(new ChartPanel(chart));
        frame.pack();
        frame.setVisible(true);
    }
    return chart;
}

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

/**
 * Some checks for the addSeries() method.
 *///from  w  w  w . ja  v a 2  s  .com
@Test
public void testAddSeries() {
    double[] values = { -1.0, 0.0, 0.1, 0.9, 1.0, 1.1, 1.9, 2.0, 3.0 };
    HistogramDataset d = new HistogramDataset();
    d.addSeries("S1", values, 2, 0.0, 2.0);
    assertEquals(0.0, d.getStartXValue(0, 0), EPSILON);
    assertEquals(1.0, d.getEndXValue(0, 0), EPSILON);
    assertEquals(4.0, d.getYValue(0, 0), EPSILON);

    assertEquals(1.0, d.getStartXValue(0, 1), EPSILON);
    assertEquals(2.0, d.getEndXValue(0, 1), EPSILON);
    assertEquals(5.0, d.getYValue(0, 1), EPSILON);
}

From source file:presenter.MainPresenter.java

@Override
public void createHistogram() {
    HistogramDataset histData = new HistogramDataset();
    histData.setType(HistogramType.FREQUENCY);
    double[] values = this.emissionsequenceModel.getEmissionsAsArray();
    histData.addSeries("H1", values, EmissionsequenceModel.EMISSIONCOUNT);

    JFreeChart chart;//from   w  w w.ja  v a2s  .com
    if (this.model != null) {
        chart = ChartFactory.createHistogram(this.model.getName(), "EmissionID", "Frequency", histData,
                PlotOrientation.VERTICAL, false, false, false);
    } else {
        chart = ChartFactory.createHistogram("unknown Model", "EmissionID", "Frequency", histData,
                PlotOrientation.VERTICAL, false, false, false);
    }
    new HistogramView(new ChartPanel(chart));
}

From source file:visualizer.projection.distance.view.DistanceHistogram.java

private IntervalXYDataset createDataset(DistanceMatrix dmat) {
    HistogramDataset histogramdataset = new HistogramDataset();
    int nrDistances = ((dmat.getElementCount() * dmat.getElementCount()) - dmat.getElementCount()) / 2;

    double[] ad = new double[nrDistances];
    int index = 0;

    for (int i = 0; i < dmat.getElementCount() - 1; i++) {
        for (int j = dmat.getElementCount() - 1; j > i; j--) {
            ad[index] = (dmat.getDistance(i, j) - dmat.getMinDistance())
                    / (dmat.getMaxDistance() - dmat.getMinDistance());
            index++;//from ww  w.  ja  va  2s .c  om
        }
    }

    histogramdataset.addSeries("", ad, 200, 0, 1);

    return histogramdataset;
}

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

/**
 * Another check for the addSeries() method.
 *//*ww w .j  av a 2s .c  o  m*/
@Test
public void testAddSeries2() {
    double[] values = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 };
    HistogramDataset hd = new HistogramDataset();
    hd.addSeries("S1", values, 5);
    assertEquals(0.0, hd.getStartXValue(0, 0), EPSILON);
    assertEquals(1.0, hd.getEndXValue(0, 0), EPSILON);
    assertEquals(1.0, hd.getYValue(0, 0), EPSILON);
    assertEquals(1.0, hd.getStartXValue(0, 1), EPSILON);
    assertEquals(2.0, hd.getEndXValue(0, 1), EPSILON);
    assertEquals(1.0, hd.getYValue(0, 1), EPSILON);
    assertEquals(2.0, hd.getStartXValue(0, 2), EPSILON);
    assertEquals(3.0, hd.getEndXValue(0, 2), EPSILON);
    assertEquals(1.0, hd.getYValue(0, 2), EPSILON);
    assertEquals(3.0, hd.getStartXValue(0, 3), EPSILON);
    assertEquals(4.0, hd.getEndXValue(0, 3), EPSILON);
    assertEquals(1.0, hd.getYValue(0, 3), EPSILON);
    assertEquals(4.0, hd.getStartXValue(0, 4), EPSILON);
    assertEquals(5.0, hd.getEndXValue(0, 4), EPSILON);
    assertEquals(2.0, hd.getYValue(0, 4), EPSILON);
}

From source file:agentlogfileanalyzer.histogram.AbstractHistogram.java

/**
 * Returns a panel containing a histogram. The data displayed in the
 * histogram is given as parameter. Data not inside the given limits is
 * discarded./*from w w w  .ja  va2s  . c o  m*/
 * 
 * @param _histogramData
 *            the data displayed in the histogram
 * @param _lowerLimit
 *            the lower limit that was entered by the user
 * @param _upperLimit
 *            the upper limit that was entered by the user
 * @return a <code>JPanel</code> containing the histogram
 */
JPanel createHistogram(Vector<Double> _histogramData, double _lowerLimit, double _upperLimit) {

    // Remove values outside the given limits...
    Vector<Double> vectorHistogramDataWithinLimits = new Vector<Double>();
    for (Iterator<Double> iterator = _histogramData.iterator(); iterator.hasNext();) {
        double d = ((Double) iterator.next()).doubleValue();
        if (valueWithinLimits(d, _lowerLimit, _upperLimit)) {
            vectorHistogramDataWithinLimits.add(d);
        }
    }

    // Store number of elements shown in histogram...
    this.numberOfVisibleClassifiers = vectorHistogramDataWithinLimits.size();

    // Convert vector to array...
    double[] arrayHistogramDataWithinLimits = new double[vectorHistogramDataWithinLimits.size()];
    for (int i = 0; i < vectorHistogramDataWithinLimits.size(); i++) {
        double d = vectorHistogramDataWithinLimits.get(i).doubleValue();
        arrayHistogramDataWithinLimits[i] = d;
    }

    if (arrayHistogramDataWithinLimits.length > 0) { // Create
        // histogram...
        HistogramDataset data = new HistogramDataset();
        data.addSeries("Suchwert", // key
                arrayHistogramDataWithinLimits, // data
                Math.max(100, arrayHistogramDataWithinLimits.length) // #bins
        );

        JFreeChart chart = ChartFactory.createHistogram(description, // title
                description, // x axis label
                "frequency", // y axis label
                data, // data
                PlotOrientation.VERTICAL, // orientation
                false, // legend
                true, // tooltips
                false // URL
        );

        return new ChartPanel(chart);
    } else {
        return createErrorPanel("No data available (within the given limits).");
    }
}

From source file:net.bioclipse.chart.ChartUtils.java

/**
 * Displays histogram of the values in ChartView
 * /* w  w w  .  j ava 2 s  .com*/
 * @param values Data values
 * @param bins Number of bins to use
 * @param xLabel X axis label
 * @param yLabel Y axis label
 * @param title Histogram title
 */
public static void histogram(double[] values, int bins, String xLabel, String yLabel, String title,
        IEditorPart dataSource) {
    setupData(values, null, xLabel, yLabel, title);
    HistogramDataset histogramData = new HistogramDataset();
    histogramData.addSeries(1, values, bins);
    chart = ChartFactory.createHistogram(title, xLabel, yLabel, histogramData, PlotOrientation.VERTICAL, false,
            false, false);

    ChartDescriptor descriptor = new ChartDescriptor(dataSource, null, ChartConstants.HISTOGRAM, xLabel,
            yLabel);

    chartManager.put(chart, descriptor);

    view.display(chart);
    ChartUtils.currentPlotType = ChartConstants.HISTOGRAM;
}

From source file:fr.ens.transcriptome.corsen.gui.qt.ResultGraphs.java

public QImage createDistanceDistributionImage(final double[] data, final int classes, final String unit) {

    if (data == null || data.length < 2)
        return null;

    HistogramDataset histogramdataset = new HistogramDataset();

    histogramdataset.addSeries("Min distances", data, classes, getMin(data), getMax(data));

    // createHistoDataSet(results.getMaxDistances(), "Max distances",
    // histogramdataset);

    JFreeChart chart = ChartFactory.createHistogram("Distribution of minimal distances",
            // title
            "Distance" + unitLegend(unit), // domain axis label
            "Cell number", // range axis label
            histogramdataset, // data

            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips?
            false // URLs?
    );//from w ww .  j  a  va  2 s  . c  om

    addTransparency(chart);

    final BufferedImage image = chart.createBufferedImage(this.width, this.height, BufferedImage.TYPE_INT_ARGB,
            null);

    return new QImage(toByte(image.getData().getDataBuffer()), this.width, this.height,
            QImage.Format.Format_ARGB32);
}