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:utils.RandomVariable.java

public static void main(String[] args) {
    double[][] value = new double[2][100000];
    for (int i = 1; i < 100000; i++) {
        //double v = RandomVariable.normal(0, 1);
        //double v = RandomVariable.cauchy(0, 1);
        //double v = RandomVariable.chi2(5);
        //double v = RandomVariable.exponential(1);
        //            double v = RandomVariable.laplace(0, 1);
        // double v = RandomVariable.laplace(-3,1);
        //double v = RandomVariable.triangular(-6, -5, -3);
        double v = RandomVariable.weibull(4, 5);
        //            if (v > 10 || v < -10) {
        //                value[0][i] = 10d;
        //            } else {
        //                value[0][i] = v;
        //            }

        //v = RandomVariable.laplace(-3,0.25);

        //            v = RandomVariable.weibull(1, 1.5);
        if (v > 10 || v < -10) {
            value[1][i] = 10d;//from   ww w  .j av  a2s .  c o  m
        } else {
            value[1][i] = v;
        }

    }
    int number = 40;
    HistogramDataset dataset = new HistogramDataset();
    dataset.setType(HistogramType.FREQUENCY);
    dataset.addSeries("Value 1", value[0], number);
    dataset.addSeries("Value 2", value[1], number);
    String plotTitle = "Histogram";
    String xaxis = "number";
    String yaxis = "value";
    PlotOrientation orientation = PlotOrientation.VERTICAL;
    boolean show = false;
    boolean toolTips = false;
    boolean urls = false;
    JFreeChart chart = ChartFactory.createHistogram(plotTitle, xaxis, yaxis, dataset, orientation, show,
            toolTips, urls);
    //        int width = 500;
    //        int height = 300;
    //        try {
    //            ChartUtilities.saveChartAsPNG(new File("histogram3.PNG"), chart, width, height);
    //        } catch (IOException e) {
    //        }
    //Display Chart
    ChartPanel chartPanel = new ChartPanel(chart);
    JFrame frame = new JFrame("Histogram plot demo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(chartPanel);
    frame.pack();
    frame.setVisible(true);

}

From source file:com.jaxzin.iraf.demo.Main.java

private static IntervalXYDataset createData(final int count) {
    final HistogramDataset data = new HistogramDataset();
    data.setType(HistogramType.SCALE_AREA_TO_1);
    data.addSeries("freq", createNormalDist(count, 0), (int) Math.round(Math.sqrt(count)));
    data.addSeries("rel_freq", createNormalDist(count, 2), (int) Math.round(Math.sqrt(count)));
    data.addSeries("area", createNormalDist(count, -2), (int) Math.round(Math.sqrt(count)));
    return data;/* w w w.  jav a2  s  . c  o m*/
}

From source file:es.uvigo.darwin.jmodeltest.io.RFHistogram.java

private static JFreeChart buildHistogram(double[] values, int steps, String plotTitle, String xAxis,
        String yAxis) {//from  ww  w  . j a va2  s  . c o m
    HistogramDataset hds = new HistogramDataset();
    hds.setType(HistogramType.RELATIVE_FREQUENCY);
    hds.addSeries(1, values, steps);
    PlotOrientation orientation = PlotOrientation.VERTICAL;
    boolean show = false;
    boolean toolTips = false;
    boolean urls = false;
    JFreeChart chart = ChartFactory.createHistogram(plotTitle, xAxis, yAxis, hds, orientation, show, toolTips,
            urls);
    return chart;
}

From source file:spminiproject.lab2.chart.Histogram2.java

private static IntervalXYDataset createDataset(String title, double vector[], int intervals) {
    HistogramDataset dataset = new HistogramDataset();
    //        double vector [] = {70, 36, 43, 69, 82, 48, 34, 62, 35, 15,
    //            59, 139, 46, 37, 42, 30, 55, 56, 36, 82,
    //            38, 89, 54, 25, 35, 24, 22, 9, 55, 19};
    // In the exercise we are asked to construct a distribution of frequencies of 8 intervals
    // That's why we put 8 in the third parameter of addSeries
    dataset.addSeries(title, vector, intervals);
    return dataset;
}

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

/**
 * Displays histogram of the values in ChartView
 * /*from  w  w  w  .j a  v a2s .co m*/
 * @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:org.gephi.ui.utils.ChartsUtils.java

/**
 * Build new histogram from the given numbers array using a default title and xLabel.
 * String dataName will be used for yLabel.
 * @param numbers Numbers for the histogram
 * @param dataName Name of the numbers data
 * @param divisions Divisions for the histogram
 * @return Prepared histogram/*w  w w . java2  s  . co  m*/
 */
public static JFreeChart buildHistogram(final Number[] numbers, final String dataName, final int divisions) {
    if (numbers == null || numbers.length == 0) {
        return null;
    }

    HistogramDataset dataset = new HistogramDataset();
    dataset.setType(HistogramType.FREQUENCY);
    double[] doubleNumbers = new double[numbers.length];
    for (int i = 0; i < doubleNumbers.length; i++) {
        doubleNumbers[i] = numbers[i].doubleValue();
    }

    dataset.addSeries(dataName, doubleNumbers, divisions > 0 ? divisions : 10);//Use 10 divisions if divisions number is invalid.

    JFreeChart histogram = ChartFactory.createHistogram(getMessage("ChartsUtils.report.histogram.title"),
            dataName, getMessage("ChartsUtils.report.histogram.yLabel"), dataset, PlotOrientation.VERTICAL,
            true, true, false);

    return histogram;
}

From source file:org.ect.reo.simulation.views.SimulationViewResults.java

private static JFreeChart createHistogram(Statistic statistic, Composite composite) {
    HistogramDataset dataset = new HistogramDataset();
    dataset.setType(HistogramType.RELATIVE_FREQUENCY);
    int numOfBatches = Integer.parseInt(SimulationViewOptions.batchNumberText.getText());
    double[] values = new double[numOfBatches];

    for (int i = 0; i < numOfBatches; i++) {
        values[i] = statistic.getStatisticValue(i);
    }/*from  w  ww .  j a  va2 s . c  o m*/

    try {
        dataset.addSeries("Histogram of batch values", values,
                (int) Math.ceil(Math.log(numOfBatches) / Math.log(2) + 1));
        return ChartFactory.createHistogram("Batch results", "Value", "Relative frequency", dataset,
                PlotOrientation.VERTICAL, false, true, false);
    } catch (Throwable t) {
        return null;
    }
}

From source file:org.matsim.contrib.parking.parkingchoice.lib.GeneralLib.java

public static void generateHistogram(String fileName, double[] value, int numberOfBins, String title,
        String xLabel, String yLabel) {
    HistogramDataset dataset = new HistogramDataset();
    dataset.setType(HistogramType.FREQUENCY);
    dataset.addSeries(title, value, numberOfBins);
    String plotTitle = title;//  w  ww  .j a va2  s  . c o m
    String xaxis = xLabel;
    String yaxis = yLabel;
    PlotOrientation orientation = PlotOrientation.VERTICAL;
    boolean show = false;
    boolean toolTips = false;
    boolean urls = false;
    JFreeChart chart = ChartFactory.createHistogram(plotTitle, xaxis, yaxis, dataset, orientation, show,
            toolTips, urls);
    int width = 500;
    int height = 300;
    try {
        ChartUtilities.saveChartAsPNG(new File(fileName), chart, width, height);
    } catch (IOException e) {

    }
}

From source file:simulation.AureoZauleckAnsLab2.java

public static JFreeChart createHistogram(ArrayList doubleMatrix, int width, String title, String label) {

    // Generate a one dimensional array of the size w*h of the double matrix
    ArrayList<Double> dataArrayList = new ArrayList<Double>();

    for (int i = 0; i < doubleMatrix.size(); i++) {

        double value = Double.parseDouble(doubleMatrix.get(i).toString());
        if (Double.isNaN(value))
            continue;
        else//from  w ww .  j a va 2 s  .c  o m
            dataArrayList.add(value);
        System.out.println(value);
    }

    double[] data = new double[dataArrayList.size()];

    for (int p = 0; p < dataArrayList.size(); p++)
        data[p] = dataArrayList.get(p);

    // int number = data.length;
    HistogramDataset dataset = new HistogramDataset();

    dataset.setType(HistogramType.FREQUENCY);
    dataset.addSeries("Hist", data, width);
    String plotTitle = title;
    String yAxis = "Frequency";
    String xAxis = label;
    PlotOrientation orientation = PlotOrientation.VERTICAL;

    boolean show = false;
    boolean toolTips = false;
    boolean urls = false;
    JFreeChart chart = ChartFactory.createHistogram(plotTitle, xAxis, yAxis, dataset, orientation, show,
            toolTips, urls);

    chart.setBackgroundPaint(Color.white);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 300));
    JFrame l = new JFrame();
    l.setContentPane(chartPanel);
    l.setSize(400, 400);
    l.setVisible(true);

    return chart;
}

From source file:iad.gui.HistogramDialog.java

private JFreeChart buildHistogram(final String title, final String xAxisLabel, final String yAxisLabel,
        final double[] numbers, final int div, final HistogramType type) {
    HistogramDataset dataset = new HistogramDataset();
    dataset.setType(type);//from w ww  .java 2 s .  com
    dataset.addSeries(xAxisLabel, numbers, div);
    JFreeChart histogram = ChartFactory.createHistogram(title, xAxisLabel, yAxisLabel, dataset,
            PlotOrientation.VERTICAL, true, true, false);

    return histogram;
}