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: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;/*  w  w  w.j a  va2 s .  c  om*/
        } 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:org.jfree.chart.demo.HistogramDemo1.java

private static IntervalXYDataset createDataset() {
    HistogramDataset histogramdataset = new HistogramDataset();
    double ad[] = new double[1000];
    Random random = new Random(0xbc614eL);
    for (int i = 0; i < 1000; i++)
        ad[i] = random.nextGaussian() + 5D;

    histogramdataset.addSeries("H1", ad, 100, 2D, 8D);
    ad = new double[1000];
    for (int j = 0; j < 1000; j++)
        ad[j] = random.nextGaussian() + 7D;

    histogramdataset.addSeries("H2", ad, 100, 4D, 10D);
    return histogramdataset;
}

From source file:testes.Histograma.java

private static IntervalXYDataset crearDataset() {
    //guarda os dados do histograma
    HistogramDataset dados = new HistogramDataset();
    int classes, min, max;

    //valores da amos
    //double amostra[] = {7,8,9,10,10,10.2,10.8,11,12,12};
    double amostra[] = { 89, 85, 93, 81, 77, 83, 87, 81, 83, 89, 81, 86, 80, 84, 82 };
    if (amostra.length <= 25) {
        classes = 5;/* www.j a v a  2s .c  o m*/
    } else {
        classes = (int) Math.round(Math.sqrt(amostra.length));
    }

    dados.addSeries("Frequncias da Amostra", amostra, classes, 77, 95);
    return dados;
}

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: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 va  2 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:baocaoxla.xuly_compare.java

public ChartPanel displayhistogram(BufferedImage image) {

    HistogramDataset dataset = new HistogramDataset();

    final int w = image.getWidth();
    final int h = image.getHeight();
    double[] r = new double[w * h];
    double[] g = new double[w * h];
    double[] b = new double[w * h];
    int dem = 0;/* ww w  .  ja  v a 2  s. co m*/
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            Color c = new Color(image.getRGB(j, i));
            r[dem] = c.getRed();
            g[dem] = c.getGreen();
            b[dem] = c.getBlue();
            dem++;
        }
    }
    //r = raster.getSamples(0, 0, w, h, 0, r);
    dataset.addSeries("Red", r, 256);
    //r = raster.getSamples(0, 0, w, h, 1, r);
    dataset.addSeries("Green", g, 256);
    // r = raster.getSamples(0, 0, w, h, 2, r);
    dataset.addSeries("Blue", b, 256);
    // chart
    JFreeChart chart = ChartFactory.createHistogram("Histogram", "Value", "Count", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    ChartPanel panel = new ChartPanel(chart);
    return panel;

}

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

public HistogramFrame(Question q) {
    String title = Translation.INSTANCE.get("misc.graphic.histogram") + " " + q.getName();
    setTitle(title);//from   w  ww  .  j ava  2s  .c o m
    HistogramDataset hist = new HistogramDataset();
    hist.setType(HistogramType.FREQUENCY);

    Set<Double> values = new TreeSet<Double>();
    q.getData().addValuesToCollection(values);
    int numOfBins = Math.min(values.size(), (q.getData().filteredLength() / 20) + 10);
    hist.addSeries(q.getName(), q.getData().getValues(), numOfBins);

    JFreeChart chart = ChartFactory.createHistogram(title, Translation.INSTANCE.get("misc.graphic.value"),
            Translation.INSTANCE.get("misc.graphic.frequency"), hist, PlotOrientation.VERTICAL, false, true,
            false);
    this.add(new ChartPanel(chart), BorderLayout.CENTER);

    this.setSize(300, 300);
    this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    this.setVisible(true);
}

From source file:pertchart.Histogram.java

public JFreeChart createHistorgram(double[] data) {

    HistogramDataset dataset = new HistogramDataset();
    dataset.setType(HistogramType.RELATIVE_FREQUENCY);
    dataset.addSeries("Histogram", data, this.bins);
    String plotTitle = "Project Completion Times";
    String xaxis = "Completion Times";
    String yaxis = "";
    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);/*from  w w  w  .j  ava 2  s  . c o m*/
    int width = 500;
    int height = 300;
    try {
        ChartUtilities.saveChartAsPNG(new File("histogram.png"), chart, width, height);
    } catch (Exception e) {
        System.out.println(e);
    }
    return chart;
}

From source file:info.opencards.ui.ltmstats.AdvancedLtmStatsPanel.java

public void rebuildPanel(Collection<CardFile> currentFiles) {
    removeAll();/*  w w w.  j  a v a2s .com*/

    // setup the stacked bar chart
    dataset = new HistogramDataset();
    //        dataset.addSeries("test", new double[]{1,2,3},1);
    final JFreeChart chart = ChartFactory.createHistogram(null, // chart title
            Utils.getRB().getString("CardTableModel.stats.weekSchedule"), // domain axis label
            //                "# cards",                     // range axis label
            null, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // the plot orientation
            false, // legend
            true, // tooltips
            false // urls
    );

    add(new ChartPanel(chart), BorderLayout.CENTER);
    //        rebuildPanel(new HashSet<CardFile>());

    if (currentFiles != null)
        this.currentFiles = currentFiles;

    //        dataset.setGroup(null);

    if (this.currentFiles == null)
        return;

    List<Double> eValues = new ArrayList<Double>();

    for (CardFile currentFile : currentFiles) {
        for (Item item : currentFile.getFlashCards().getLTMItems()) {
            LTMItem ltmItem = (LTMItem) item;
            eValues.add(ltmItem.getEFactor());
        }
    }
    double[] eVals = new double[eValues.size()];
    for (int i = 0; i < eValues.size(); i++) {
        eVals[i] = eValues.get(i);

    }

    if (eVals.length > 0)
        dataset.addSeries("test", eVals, 10);

    HistogramDataset dataset1 = new HistogramDataset();
    dataset1.addSeries("test", eVals, 10);

    repaint();

    //        computeScheduleHist(this.currentFiles);
    //        set2EDistribution(currentFiles);
}

From source file:gui.Histograma.java

private static IntervalXYDataset criarDataset() {
    //guarda os dados do histograma
    HistogramDataset dados = new HistogramDataset();
    int classes;//from   w  w  w.j  a va 2  s.com
    double valores[] = new double[amostra.size()];

    //Definindo quantidade de classes
    if (amostra.size() <= 25) {
        classes = 5;
    } else {
        classes = (int) Math.round(Math.sqrt(amostra.size()));
    }
    //Criando vetor com valores da amostra
    for (int i = 0; i < amostra.size(); i++) {
        valores[i] = amostra.get(i);
    }

    //Adicionando os dataset para o histograma
    dados.addSeries("Frequncia das Amostras", valores, classes, min, max);
    return dados;
}