Example usage for org.jfree.chart ChartFactory createHistogram

List of usage examples for org.jfree.chart ChartFactory createHistogram

Introduction

In this page you can find the example usage for org.jfree.chart ChartFactory createHistogram.

Prototype

public static JFreeChart createHistogram(String title, String xAxisLabel, String yAxisLabel,
        IntervalXYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips,
        boolean urls) 

Source Link

Document

Creates a histogram chart.

Usage

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  ww  w.  j  a  v  a  2 s . c om
    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:flow.visibility.pcap.FlowProcess.java

private static JFreeChart createChart(XYSeriesCollection dataset) {

    /** The function to create the chart */

    JFreeChart Chart = ChartFactory.createHistogram("Number Packets of Flows", "Flow Number",
            "Number of Packets", dataset, PlotOrientation.VERTICAL, false, false, false);
    Chart.getXYPlot().setForegroundAlpha(0.75f);

    return Chart;

}

From source file:ImageProcessing.ImageProcessing.java

public static JFreeChart createHistogram(double[] dataset_values, Color barColor) {
    //Creates a histogram based on passed values and bar colors.        
    HistogramDataset dataset = new HistogramDataset();
    dataset.addSeries("Values", dataset_values, 255, 0, 255);

    JFreeChart chart = ChartFactory.createHistogram(null, //Title
            null, //X Label
            null, //Y Label
            dataset, //Dataset
            org.jfree.chart.plot.PlotOrientation.VERTICAL, //Plot orientation
            true, false, false); //Other details

    //Remove chart legends to save space, we don't really need them anyway
    chart.removeLegend();/*from   w  w  w  . j  av a 2 s . c om*/
    //Set bar colors according to the parameter passed.
    XYItemRenderer renderer = chart.getXYPlot().getRenderer();
    renderer.setSeriesPaint(0, barColor);
    //Set background to null (the background will be similar to frame color in display.
    chart.setBackgroundPaint(null);

    return chart;
}

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 ww  .j a  v a2s. 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: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.  j  a  va  2  s .  com
    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:tarea1.histogram.java

private ChartPanel createChartPanel() {
    // dataset//from   w  w w  .j  a v  a 2s . com
    HistogramDataset dataset = new HistogramDataset();
    Raster raster = image.getRaster();
    final int w = image.getWidth();
    final int h = image.getHeight();
    double[] r = new double[w * h];
    r = raster.getSamples(0, 0, w, h, 0, r);
    dataset.addSeries("Red", r, BINS);
    r = raster.getSamples(0, 0, w, h, 1, r);
    dataset.addSeries("Green", r, BINS);
    r = raster.getSamples(0, 0, w, h, 2, r);
    dataset.addSeries("Blue", r, BINS);
    // chart
    JFreeChart chart = ChartFactory.createHistogram("Histogram", "Value", "Count", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setBarPainter(new StandardXYBarPainter());
    // translucent red, green & blue
    Paint[] paintArray = { new Color(0x80ff0000, true), new Color(0x8000ff00, true),
            new Color(0x800000ff, true) };
    plot.setDrawingSupplier(
            new DefaultDrawingSupplier(paintArray, DefaultDrawingSupplier.DEFAULT_FILL_PAINT_SEQUENCE,
                    DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
                    DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
                    DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
                    DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE));
    ChartPanel panel = new ChartPanel(chart);
    panel.setMouseWheelEnabled(true);
    return panel;
}

From source file:gui.Histograma.java

private static JFreeChart gerarGrafico(IntervalXYDataset dados) {
    JFreeChart chart = ChartFactory.createHistogram("Histograma", null, null, dados, PlotOrientation.VERTICAL,
            true, true, false);//from  w w  w  . j  av a2s . co m
    XYPlot plot = (XYPlot) chart.getPlot();
    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(true);
    return chart;
}

From source file:org.codehaus.mojo.chronos.chart.HistogramChartGenerator.java

protected final JFreeChart createHistogramChart(ResponsetimeSamples samples, String label,
        ResourceBundle bundle, ReportConfig config) {
    HistogramDataset histogramdataset = new HistogramDataset();

    double[] sampleArray = samples.extractResponsetimes(config.getResponsetimedivider());
    histogramdataset.addSeries(label, sampleArray, BINS);
    HistogramDataset dataset = histogramdataset;
    JFreeChart chart = ChartFactory.createHistogram(bundle.getString("chronos.label.histogram"),
            bundle.getString("chronos.label.histogram.x"), bundle.getString("chronos.label.histogram.y"),
            dataset, PlotOrientation.VERTICAL, true, false, false);
    XYPlot xyplot = (XYPlot) chart.getPlot();
    xyplot.setForegroundAlpha(FOREGROUND_ALPHA);
    XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer();
    xybarrenderer.setDrawBarOutline(false);

    if (config.isShowpercentile()) {
        String label1 = bundle.getString("chronos.label.percentile95.arrow");
        double value = samples.getPercentile95(config.getResponsetimedivider());
        ChartUtil.addDomainMarker(xyplot, label1, value);
    }/*from  www .j  a v  a  2s.  c  o m*/
    if (config.isShowaverage()) {
        String label2 = bundle.getString("chronos.label.average.arrow");
        double value = samples.getAverage(config.getResponsetimedivider());
        ChartUtil.addDomainMarker(xyplot, label2, value);
    }
    return chart;
}

From source file:de.fub.maps.project.detector.model.statistics.HistogramPanel.java

/**
 * Creates new form histogramPanel/*from w ww  .  j a  v  a 2  s .  c o  m*/
 */
public HistogramPanel() {
    initComponents();
    histogramChart = ChartFactory.createHistogram(null, null, null, dataSet, PlotOrientation.VERTICAL, false,
            true, true);
    plot = histogramChart.getXYPlot();
    chartPanel = new ChartPanel(histogramChart, true);
    add(chartPanel, BorderLayout.CENTER);
    XYBarRenderer barRenderer = new XYBarRenderer(.05);
    barRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    barRenderer.setBarPainter(new StandardXYBarPainter());
    barRenderer.setBarAlignmentFactor(.1);
    barRenderer.setBasePaint(Color.blue);
    //        barRenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
    barRenderer.setBaseItemLabelGenerator(
            new StandardXYItemLabelGenerator(StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT,
                    new CustomNumberFormat(), new CustomNumberFormat()));
    barRenderer.setBaseItemLabelsVisible(true);
    plot.setRenderer(barRenderer);
    plot.setBackgroundPaint(Color.white);
    histogramChart.setBackgroundPaint(Color.white);
    plot.setRangeGridlinesVisible(true);
    chartPanel.setVerticalAxisTrace(false);
    chartPanel.setDisplayToolTips(true);
    chartPanel.setBackground(Color.white);
}

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

protected void buildChart() {
    HistogramDataset dataset = new HistogramDataset();
    dataset.setType(HistogramType.FREQUENCY); // when buildChart() is called, histogramType hasn't been set yet.

    chart = ChartFactory.createHistogram("Untitled Chart", "Untitled X Axis", "Untitled Y Axis", dataset,
            PlotOrientation.VERTICAL, false, true, false);
    chart.setAntiAlias(true);/*w w  w.  ja v  a 2s  . c  o  m*/
    //chartPanel = new ScrollableChartPanel(chart, true);         
    chartPanel = buildChartPanel(chart);
    setChartPanel(chartPanel);
    //chartHolder.getViewport().setView(chartPanel);
    ((XYBarRenderer) (chart.getXYPlot().getRenderer())).setShadowVisible(false);
    ((XYBarRenderer) (chart.getXYPlot().getRenderer())).setBarPainter(new StandardXYBarPainter());

    // this must come last because the chart must exist for us to set its dataset
    setSeriesDataset(dataset);
}