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:org.jfree.expdemo.SelectionDemo4.java

/**
 * Creates a chart.//from  w w w . j av a 2  s  .co  m
 * 
 * @param dataset
 *            a dataset.
 * 
 * @return The chart.
 */
private static JFreeChart createChart(IntervalXYDataset dataset, DatasetSelectionExtension ext) {
    JFreeChart chart = ChartFactory.createHistogram("SelectionDemo4", null, null, dataset,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainPannable(true);
    plot.setRangePannable(true);
    plot.setForegroundAlpha(0.85f);
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(true);
    renderer.setBaseOutlinePaint(Color.red);
    renderer.setBarPainter(new StandardXYBarPainter());
    renderer.setShadowVisible(false);

    //add selection specific rendering
    IRSUtilities.setSelectedItemPaint(renderer, ext, Color.white);

    //register plot as selection change listener
    ext.addSelectionChangeListener(plot);

    return chart;
}

From source file:edu.wisc.ssec.mcidasv.control.McIDASVHistogramWrapper.java

/**
 * Create the chart.//from  w w w  .  j  a v  a  2  s  . com
 */
private void createChart() {
    if (chartPanel != null) {
        return;
    }

    MyHistogramDataset dataset = new MyHistogramDataset();
    chart = ChartFactory.createHistogram("Histogram", null, null, dataset, PlotOrientation.VERTICAL, false,
            false, false);
    chart.getXYPlot().setForegroundAlpha(0.75f);
    plot = (XYPlot) chart.getPlot();
    initXYPlot(plot);
    chartPanel = doMakeChartPanel(chart);
}

From source file:Demo.HistGraph.java

private JFreeChart CreateChart(String para) {
    // read .dat file
    double[] value = Utils.GetParaTab(para);

    // generate chart
    HistogramDataset dataset = new HistogramDataset();
    dataset.setType(HistogramType.FREQUENCY);
    dataset.addSeries(para, value, 20);//from   w  w  w  . j a v  a2s .  c  om

    String plotTitle = para;
    String xaxis = "value";
    String yaxis = "frequecy";
    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);

    final XYPlot xyPlot = chart.getXYPlot();
    final XYBarRenderer renderer = (XYBarRenderer) xyPlot.getRenderer();
    renderer.setSeriesPaint(0, Color.BLUE);

    return chart;
}

From source file:gda.gui.dv.panels.vispanels.ColourSelector.java

/**
 * The function that performs the histogram Drawing
 * /*from  w ww .j  a va2 s. c  o  m*/
 * @param raw
 *            the raw data
 * @return the new data in the appropriate form
 */
@Override
public ImageData cast(DoubleDataset raw) {

    dataLink = raw;

    if (max == null) {
        max = raw.max().doubleValue();
    }
    if (min == null) {
        min = raw.min().doubleValue();
    }

    ImageData result = colourCast(raw, max, min);

    // if old stuff exists then remove it.
    if (chart != null) {
        chart.removeAll();
    }

    // now plot the histogram

    HistogramDataset histData = new HistogramDataset();
    histData.addSeries("h1", raw.getData(), 100, min, max);
    histogram = ChartFactory.createHistogram("Histogram", "Value", "Counts", histData, PlotOrientation.VERTICAL,
            false, false, false);

    if (unconfigured == false) {
        this.remove(chart);
    }
    unconfigured = false;

    chart = new DrawChart(histogram);

    chart.setMouseZoomable(false);

    chart.setPreferredSize(new Dimension(300, 300));
    chart.setMinimumSize(new Dimension(200, 200));

    c.gridx = 0;
    c.gridy = 4;
    c.gridwidth = 2;

    this.add(chart, c);

    chart.addMouseListener(new MouseListener() {
        Double tmin = min;
        Double tmax = max;

        @Override
        public void mouseClicked(MouseEvent e) {

        }

        @Override
        public void mouseEntered(MouseEvent e) {

        }

        @Override
        public void mouseExited(MouseEvent e) {

        }

        @Override
        public void mousePressed(MouseEvent e) {
            SimpleDataCoordinate coordinates = convertMouseEvent(e);
            if (chart.getScreenDataArea().contains(e.getX(), e.getY())) {
                tmin = coordinates.getX();
            } else {
                if (chart.getScreenDataArea().outcode(e.getX(), e.getY()) != Rectangle2D.OUT_RIGHT) {
                    //                  System.out.println("out of bounds");
                    //                  System.out.printf("Mouse: %d\n", e.getX());
                } else {
                    tmin = max;
                }
            }

        }

        @Override
        public void mouseReleased(MouseEvent e) {
            boolean update = false;
            SimpleDataCoordinate coordinates = convertMouseEvent(e);

            if (chart.getScreenDataArea().contains(e.getX(), e.getY())) {
                tmax = coordinates.getX();
                update = true;
            } else {
                if (chart.getScreenDataArea().outcode(e.getX(), e.getY()) != Rectangle2D.OUT_LEFT) {
                    //                  System.out.println("out of bounds");
                    //                  System.out.printf("Mouse: %d\n", e.getX());
                } else {
                    tmax = min;
                    update = true;
                }
            }
            if (update && tmin != tmax) {
                if (tmin > tmax) { // check and correct limits
                    Double t = tmin;
                    tmin = tmax;
                    tmax = t;
                }
                min = tmin;
                max = tmax;

                owner.getDataSetImage().applyColorCast();
                owner.getDataSetPlot3D().applyColorCast();
                owner.getDataSetImage().repaint();
            }
        }

        public SimpleDataCoordinate convertMouseEvent(MouseEvent me) {
            return new SimpleDataCoordinate(

                    histogram.getXYPlot().getDomainAxis().java2DToValue(me.getX(), chart.getScreenDataArea(),
                            histogram.getXYPlot().getDomainAxisEdge()),

                    histogram.getXYPlot().getRangeAxis().java2DToValue(me.getY(), chart.getScreenDataArea(),
                            histogram.getXYPlot().getRangeAxisEdge()));

        }

    });

    lblchart.invalidate();
    lblchart.validate();

    this.invalidate();
    this.validate();

    return result;

}

From source file:piilSource.Histogram.java

private static JFreeChart createChart(String s, IntervalXYDataset intervalxydataset, String metaLabel) {
    JFreeChart jfreechart = ChartFactory.createHistogram(
            "Histogram of the " + metaLabel + " values for all samples - " + s, null, null, intervalxydataset,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setForegroundAlpha(0.85F);//from w  w w.  j  a v  a  2  s  . c om
    XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer();
    xybarrenderer.setDrawBarOutline(false);
    return jfreechart;
}

From source file:org.encog.workbench.tabs.visualize.weights.AnalyzeWeightsTab.java

/**
 * Creates a chart.//  w ww .ja  v a  2  s.  com
 * 
 * @param dataset  a dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(IntervalXYDataset dataset) {
    JFreeChart chart = ChartFactory.createHistogram(null, null, null, dataset, PlotOrientation.VERTICAL, true,
            false, false);
    chart.getXYPlot().setForegroundAlpha(0.75f);
    return chart;
}

From source file:sim.app.sugarscape.Charts.java

JFreeChart createChart4() {
    JFreeChart chart4 = ChartFactory.createHistogram("Wealth Distribution", "Wealth", "Count", model.dataset,
            PlotOrientation.VERTICAL, true, true, false);
    model.chart4 = chart4;//from  ww w  .ja  va 2 s  .com
    NumberAxis rangeAxis1 = new NumberAxis("Wealth");
    rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    org.jfree.chart.axis.NumberAxis domainAxis = new NumberAxis("Bins");
    XYPlot plot = chart4.getXYPlot();
    XYItemRenderer renderer1 = plot.getRenderer();
    renderer1.setSeriesPaint(0, Color.MAGENTA);
    return chart4;
}

From source file:org.jfree.chart.demo.HistogramDemo.java

/**
 * Creates a chart./*from   w  w w.  j  a  va2 s  . c  om*/
 * 
 * @param dataset  a dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final IntervalXYDataset dataset) {
    final JFreeChart chart = ChartFactory.createHistogram("Histogram Demo", null, null, dataset,
            PlotOrientation.VERTICAL, true, false, false);
    chart.getXYPlot().setForegroundAlpha(0.75f);
    return chart;
}

From source file:imageviewer.tools.HistogramTool.java

public void plot(MouseEvent e) {

    if (e.getSource() instanceof ImagePanel) {
        Image image = ((ImagePanel) e.getSource()).getSource();
        Histogram h = image.getHistogram();
        SimpleHistogramDataset shd = new SimpleHistogramDataset("Voxel distribution");
        for (int i = 0, numBands = h.getNumBands(); i < numBands; i++) {
            int[] binData = h.getBins(i);
            for (int j = 0; j < binData.length; j++) {
                SimpleHistogramBin shb = new SimpleHistogramBin(j - 0.5, j + 0.5, true, false);
                shb.setItemCount(binData[j]);
                shd.addBin(shb);//from   w  w  w.  j  a va2  s . c o m
            }
        }
        double[] domainBounds = null, rangeBounds = null;
        if (chart != null) {
            ValueAxis va = chart.getXYPlot().getDomainAxis();
            domainBounds = new double[] { va.getLowerBound(), va.getUpperBound() };
            va = chart.getXYPlot().getRangeAxis();
            rangeBounds = new double[] { va.getLowerBound(), va.getUpperBound() };
        }
        chart = ChartFactory.createHistogram(null, "Voxel value", "Count", shd, PlotOrientation.VERTICAL, false,
                true, false);
        chart.setBackgroundPaint(new Color(20, 30, 45));
        chart.setAntiAlias(true);
        ValueAxis domainAxis = chart.getXYPlot().getDomainAxis();
        domainAxis.setLabelFont(axisFont);
        domainAxis.setTickLabelFont(tickFont);
        domainAxis.setAxisLinePaint(Color.white);
        domainAxis.setTickLabelPaint(Color.white);
        domainAxis.setLabelPaint(Color.white);
        if (domainBounds != null) {
            domainAxis.setAutoRange(false);
            domainAxis.setLowerBound(domainBounds[0]);
            domainAxis.setUpperBound(domainBounds[1]);
        } else {
            domainAxis.setLowerBound(0);
        }
        ValueAxis rangeAxis = chart.getXYPlot().getRangeAxis();
        rangeAxis.setLabelFont(axisFont);
        rangeAxis.setTickLabelFont(tickFont);
        rangeAxis.setAxisLinePaint(Color.white);
        rangeAxis.setTickLabelPaint(Color.white);
        rangeAxis.setLabelPaint(Color.white);
        if (rangeBounds != null) {
            rangeAxis.setAutoRange(false);
            rangeAxis.setLowerBound(rangeBounds[0]);
            rangeAxis.setUpperBound(rangeBounds[1]);
        }
        chart.getXYPlot().getRenderer().setSeriesPaint(0, new Color(0, 51, 113));
        ((XYBarRenderer) chart.getXYPlot().getRenderer()).setDrawBarOutline(false);
        chart.getXYPlot().setBackgroundAlpha(0.05f);

        double[] mean = h.getMean();
        double[] sd = h.getStandardDeviation();
        IntervalMarker im = new IntervalMarker(mean[0] - sd[0] / 2, mean[0] + sd[0] / 2);
        im.setPaint(new Color(200, 200, 200, 128));
        chart.getXYPlot().addDomainMarker(0, im, Layer.BACKGROUND);
        cp.setChart(chart);
    }
}

From source file:chart.statistic.HistogramChart.java

public ChartPanel createChartPanel() {

    chart = ChartFactory.createHistogram(mr.getLabel(), null, null, dataset, PlotOrientation.VERTICAL,
            useLegend, // legende
            false, false);//ww w .j  a va 2  s .c om
    chart.getXYPlot().setForegroundAlpha(0.75f);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(widthD, heightD));

    return chartPanel;
}