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

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

Introduction

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

Prototype

public void addSeries(Comparable key, double[] values, int bins) 

Source Link

Document

Adds a series to the dataset, using the specified number of bins, and sends a DatasetChangeEvent to all registered listeners.

Usage

From source file:edu.gmu.cs.sim.util.media.chart.HistogramGenerator.java

/** Adds a series, plus a (possibly null) SeriesChangeListener which will receive a <i>single</i>
 event if/when the series is deleted from the chart by the user. Returns the series attributes. */
public SeriesAttributes addSeries(double[] vals, int bins, String name, SeriesChangeListener stopper) {
    if (vals == null || vals.length == 0) {
        vals = new double[] { 0 }; // ya gotta have at least one val
    }/*from w ww . j a  va 2s  .  c  o  m*/
    HistogramDataset dataset = (HistogramDataset) (getSeriesDataset());
    int i = dataset.getSeriesCount();
    dataset.setType(histogramType); // It looks like the histograms reset
    dataset.addSeries(new UniqueString(name), vals, bins);

    // need to have added the dataset BEFORE calling this since it'll try to change the name of the series
    HistogramSeriesAttributes csa = new HistogramSeriesAttributes(this, name, i, vals, bins, stopper);
    seriesAttributes.add(csa);

    revalidate(); // display the new series panel
    update();

    // won't update properly unless I force it here by letting all the existing scheduled events to go through.  Dumb design.  :-(
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            update();
        }
    });

    return csa;
}

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  ww w.java  2 s. c o  m*/
    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:edu.gmu.cs.sim.util.media.chart.HistogramGenerator.java

protected void update() {
    // We have to rebuild the dataset from scratch (deleting and replacing it) because JFreeChart's
    // histogram facility doesn't have a way to remove or move elements.  Stupid stupid stupid.

    SeriesAttributes[] sa = getSeriesAttributes();
    HistogramDataset dataset = new HistogramDataset();
    dataset.setType(histogramType);//from   w  ww.j a  v a2 s.  com

    for (int i = 0; i < sa.length; i++) {
        HistogramSeriesAttributes attributes = (HistogramSeriesAttributes) (sa[i]);
        dataset.addSeries(new UniqueString(attributes.getSeriesName()), attributes.getValues(),
                attributes.getNumBins());
    }

    setSeriesDataset(dataset);
}

From source file:com.compomics.cell_coord.gui.controller.computation.ComputationDataController.java

/**
 *
 * @param track/* w  ww .  j  av a 2s. co m*/
 */
private void plotDisplacements(Track track) {
    double[] values = ArrayUtils.toPrimitive(ComputationUtils.excludeNullValues(track.getStepDisplacements()));
    HistogramDataset histogramDataset = new HistogramDataset();
    histogramDataset.addSeries("", values, 5);
    String title = "displacements for track: " + track.getTrackid();
    JFreeChart jFreeChart = ChartFactory.createHistogram(title, "displ", "count", histogramDataset,
            PlotOrientation.VERTICAL, true, true, true);
    ChartPanel chartPanel = new ChartPanel(jFreeChart);
    computationDataPanel.getDisplPlotPanel().removeAll();
    computationDataPanel.getDisplPlotPanel().add(chartPanel, gridBagConstraints);
    computationDataPanel.getDisplPlotPanel().revalidate();
    computationDataPanel.getDisplPlotPanel().repaint();
}

From source file:com.compomics.cell_coord.gui.controller.computation.ComputationDataController.java

/**
 *
 * @param track//from   www.  j  a va 2s.  c  om
 */
private void plotAngles(Track track) {
    double[] values = ArrayUtils.toPrimitive(ComputationUtils.excludeNullValues(track.getAngles()));
    HistogramDataset histogramDataset = new HistogramDataset();
    histogramDataset.addSeries("", values, 5);
    String title = "angles for track: " + track.getTrackid();
    JFreeChart jFreeChart = ChartFactory.createHistogram(title, "angle", "count", histogramDataset,
            PlotOrientation.VERTICAL, true, true, true);
    ChartPanel chartPanel = new ChartPanel(jFreeChart);
    computationDataPanel.getAnglePlotPanel().removeAll();
    computationDataPanel.getAnglePlotPanel().add(chartPanel, gridBagConstraints);
    computationDataPanel.getAnglePlotPanel().revalidate();
    computationDataPanel.getAnglePlotPanel().repaint();
}

From source file:com.compomics.cell_coord.gui.controller.computation.ComputationDataController.java

/**
 *
 * @param track//from w w  w.  j  a  v  a 2s.  c  o m
 */
private void plotDeltaX(Track track) {
    Double[] deltaXValues = ComputationUtils.transpose2DArray(track.getSteps())[0];
    double[] values = ArrayUtils.toPrimitive(ComputationUtils.excludeNullValues(deltaXValues));
    HistogramDataset histogramDataset = new HistogramDataset();
    histogramDataset.addSeries("", values, 2);
    String title = "delta_x_values for track: " + track.getTrackid();
    JFreeChart jFreeChart = ChartFactory.createHistogram(title, "delta_x", "count", histogramDataset,
            PlotOrientation.VERTICAL, true, true, true);
    ChartPanel chartPanel = new ChartPanel(jFreeChart);
    computationDataPanel.getDeltaxPlotPanel().removeAll();
    computationDataPanel.getDeltaxPlotPanel().add(chartPanel, gridBagConstraints);
    computationDataPanel.getDeltaxPlotPanel().revalidate();
    computationDataPanel.getDeltaxPlotPanel().repaint();
}

From source file:com.compomics.cell_coord.gui.controller.computation.ComputationDataController.java

/**
 *
 * @param track//from   w w w .  jav  a 2  s.  c  om
 */
private void plotDeltaY(Track track) {
    Double[] deltaYValues = ComputationUtils.transpose2DArray(track.getSteps())[1];
    double[] values = ArrayUtils.toPrimitive(ComputationUtils.excludeNullValues(deltaYValues));
    HistogramDataset histogramDataset = new HistogramDataset();
    histogramDataset.addSeries("", values, 2);
    String title = "delta_y_values for track: " + track.getTrackid();
    JFreeChart jFreeChart = ChartFactory.createHistogram(title, "delta_y", "count", histogramDataset,
            PlotOrientation.VERTICAL, true, true, true);
    ChartPanel chartPanel = new ChartPanel(jFreeChart);
    computationDataPanel.getDeltayPlotPanel().removeAll();
    computationDataPanel.getDeltayPlotPanel().add(chartPanel, gridBagConstraints);
    computationDataPanel.getDeltayPlotPanel().revalidate();
    computationDataPanel.getDeltayPlotPanel().repaint();
}

From source file:herbie.running.analysis.ModeSharesEventHandler.java

public HistogramDataset getHistogramDataset(final int nBins) {
    HistogramDataset output = new HistogramDataset();
    output.setType(HistogramType.RELATIVE_FREQUENCY);

    for (String mode : this.rawData.keySet()) {
        output.addSeries(mode, this.rawData.get(mode).getElements(), nBins);
    }//from   w  w  w  . j ava  2s  .co m

    return output;
}

From source file:org.geopublishing.atlasStyler.classification.RasterClassification.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  a v  a 2  s .  c o  m*/
    valuesAL = getStatistics().elements();
    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(getSD(), 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(getMean(), 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.deegree.test.gui.StressTestController.java

private void drawDiagram(HttpServletResponse response, int width, int height) throws IOException {

    int n = resultData.size();
    double[] values = new double[n];
    for (int i = 0; i < n; i++)
        values[i] = resultData.get(i).getTimeElapsed() / 1000.0;

    HistogramDataset dataset = new HistogramDataset();
    dataset.addSeries(new Double(1.0), values, n);

    JFreeChart chart = ChartFactory.createHistogram("timeVSfreq", "time", "frequency", dataset,
            PlotOrientation.VERTICAL, true, true, true);

    ChartRenderingInfo info = new ChartRenderingInfo();
    BufferedImage buf = chart.createBufferedImage(width, height, 1, info);

    response.setContentType("image/jpeg");
    OutputStream out = response.getOutputStream();
    ImageIO.write(buf, "jpg", out);
    out.close();//from  ww  w  .  ja  v  a 2 s .  com

}