Example usage for org.jfree.chart ChartFactory createBarChart

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

Introduction

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

Prototype

public static JFreeChart createBarChart(String title, String categoryAxisLabel, String valueAxisLabel,
        CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) 

Source Link

Document

Creates a bar chart.

Usage

From source file:com.choicemaker.cm.modelmaker.gui.panels.StatisticsHistogramPanel.java

private void buildPanel() {
    final PlotOrientation orientation = PlotOrientation.VERTICAL;
    data = new HistoCategoryDataset(SERIES, getNumBins());
    histogram = ChartFactory.createBarChart(
            ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.histogram.cm.accuracy"),
            ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.histogram.cm.matchprob"),
            ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.histogram.cm.numpairs"), data,
            orientation, true, true, true);
    histogram.setBackgroundPaint(getBackground());
    CategoryPlot plot = (CategoryPlot) histogram.getPlot();
    plot.setForegroundAlpha(0.9f);//w  ww. jav a 2s  .  c o m
    //      HorizontalCategoryAxis axis = (HorizontalCategoryAxis) plot.getDomainAxis();
    CategoryAxis axis = plot.getDomainAxis();
    axis.setLowerMargin(0.02);
    axis.setUpperMargin(0.02);
    axis.setCategoryMargin(0.2);
    //      axis.setVerticalCategoryLabels(true);
    CategoryItemRenderer renderer = plot.getRenderer();
    whSeriesPaint = new Paint[3];
    for (int i = 0; i < whSeriesPaint.length; ++i) {
        //         whSeriesPaint[i] = renderer.getSeriesPaint(0, i);
        whSeriesPaint[i] = renderer.getSeriesPaint(i);
    }
    wohSeriesPaint = new Paint[2];
    wohSeriesPaint[0] = whSeriesPaint[0];
    wohSeriesPaint[1] = whSeriesPaint[2];
    //   plot.setRangeAxis(new VerticalLogarithmicAxis());
    histoPanel = new HistoChartPanel(histogram, false, false, false, true, true, parent.getModelMaker());
    //   histoPanel.setEnabled(false);

    binWidthLabel = new JLabel(
            ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.histogram.binwidth"));
    binWidthField = new JTextField(Float.toString(binWidth), 4);
    binWidthField.setMinimumSize(new Dimension(50, 20));
}

From source file:org.mili.jmibs.jfree.JFreeChartBarIterationIntervalBenchmarkSuiteResultRenderer.java

private JFreeChart createChart(String title, CategoryDataset dataset) {
    JFreeChart chart = ChartFactory.createBarChart(title, "Benchmark (Iteration/Interval)", "Time in ns",
            dataset, PlotOrientation.HORIZONTAL, true, true, false);
    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);/*  www .  ja va  2  s  . com*/
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    return chart;
}

From source file:org.fhcrc.cpl.toolbox.gui.chart.PanelWithBarChart.java

protected void init() {
    dataset = new DefaultCategoryDataset();
    JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.VERTICAL, true,
            false, false);/*  www. ja va 2  s .co  m*/

    init(chart.getPlot());
}

From source file:org.matsim.counts.algorithms.graphs.CountsGEHCurveGraph.java

@Override
public JFreeChart createChart(final int nbr) {
    String title = this.getChartTitle() + ", Iteration: " + this.iteration_;
    this.chart_ = ChartFactory.createBarChart(title, "Hour", "GEH", this.dataset, PlotOrientation.VERTICAL,
            false, // legend?
            false, // tooltips?
            false // URLs?
    );/* ww  w .  jav a2s.  c  om*/
    CategoryPlot plot = this.chart_.getCategoryPlot();
    //      plot.getRangeAxis().setRange(0.0, 10000.0); // do not set a fixed range for the single link graphs
    plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    // BarRenderer renderer=(BarRenderer) plot.getRenderer();
    //      BarRenderer renderer = new BarRenderer();
    /*
     * Chooses the color adaptive based on the value to be shown by a bar.
     * Values <= 5.0 are green, values >= 10 are red. In between the color is interpolated. 
     */
    BarRenderer renderer = new BarRenderer() {
        @Override
        public Paint getItemPaint(final int row, final int column) {
            double value = dataset.getValue(row, column).doubleValue();

            if (value <= 5.0)
                return Color.green;
            else if (value >= 10)
                return Color.red;
            else {
                if (value < 7.5) {
                    int mixed = mix(Color.yellow.getRGB(), Color.green.getRGB(), (7.5 - value) / 2.5);
                    return new Color(mixed);
                } else {
                    int mixed = mix(Color.red.getRGB(), Color.yellow.getRGB(), (10.0 - value) / 2.5);
                    return new Color(mixed);
                }
            }

            //            if (value <= 5.0) return Color.green;
            //            else if (value >= 10) return Color.red;
            //            else {
            //               int mixed = mix(Color.red.getRGB(), Color.green.getRGB(), (10.0 - value) / 5.0);
            //               return new Color(mixed);
            //            }
        }
    };
    renderer.setSeriesOutlinePaint(0, Color.black);
    renderer.setSeriesPaint(0, Color.getHSBColor((float) 0.62, (float) 0.56, (float) 0.93));
    renderer.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator());
    renderer.setItemMargin(0.0);

    // configure plot with light colors instead of the default 3D
    renderer.setShadowVisible(false);
    renderer.setBarPainter(new StandardBarPainter());
    this.chart_.setBackgroundPaint(Color.getHSBColor((float) 0.0, (float) 0.0, (float) 0.93));
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.gray);
    plot.setRangeGridlinesVisible(true);

    plot.setRenderer(0, renderer);
    plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
    plot.mapDatasetToRangeAxis(1, 1);

    final CategoryAxis axis1 = plot.getDomainAxis();
    axis1.setCategoryMargin(0.25); // leave a gap of 25% between categories

    return this.chart_;
}

From source file:fr.paris.lutece.plugins.form.business.GraphTypeBarChart.java

/**
* return the JFreeChart BarChart graph/*from  w  w w .j  ava 2s .c om*/
* @param listStatistic listStatistic
* @param strGraphTitle graph title
* @param nGraphThreeDimension true if the graph must be in three dimension
* @param nGraphLabelValue true if the labels must appear in the graph
* @return the JFreeChart graph associate to the graph type
*/

//Cration de l'histogramme
public static JFreeChart createBarChart(List<StatisticEntrySubmit> listStatistic, String strGraphTitle,
        boolean nGraphThreeDimension, boolean nGraphLabelValue) {
    JFreeChart chart;
    CategoryDataset dataset = createBarChartDataset(listStatistic);

    if (nGraphThreeDimension) {
        chart = ChartFactory.createBarChart3D(strGraphTitle, null, null, dataset, PlotOrientation.VERTICAL,
                true, false, false);
    } else {
        chart = ChartFactory.createBarChart(strGraphTitle, null, null, dataset, PlotOrientation.VERTICAL, true,
                false, false);
    }

    CategoryPlot categoryPlot = chart.getCategoryPlot();
    CategoryAxis categoryAxis = categoryPlot.getDomainAxis();
    CategoryLabelPositions labelPositions = CategoryLabelPositions.UP_45;
    categoryAxis.setCategoryLabelPositions(labelPositions);

    BarRenderer renderer = (BarRenderer) categoryPlot.getRenderer();

    if (nGraphLabelValue) {
        renderer.setItemLabelsVisible(true);

        DecimalFormat decimalformat1 = new DecimalFormat("#.#");
        renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", decimalformat1));

        if (nGraphThreeDimension) {
            renderer.setPositiveItemLabelPositionFallback(
                    new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.BASELINE_LEFT));
            categoryPlot.setRenderer(renderer);
        }
    }

    return chart;
}

From source file:com.liferay.samplestrutsliferay.struts.action.ViewChartAction.java

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    try {//from   ww  w .  jav  a2s .co  m
        if (_log.isInfoEnabled()) {
            _log.info("execute");
        }

        String attrName = "chart_name";

        // Application scoped session attributes can be fetched from the
        // servlet directly. Portlet scoped session attributes can be
        // fetched from Sun's PortletSessionUtil.

        HttpSession session = request.getSession();

        String chartName = (String) session.getAttribute(attrName);
        //(String)_getAttribute(request, attrName);

        // Chart

        String chartType = request.getParameter("chart_type");

        CategoryDataset dataset = _getDataset();

        String xName = "Soda";
        String yName = "Votes";

        JFreeChart chart = null;

        if (chartType.equals("area")) {
            chart = ChartFactory.createAreaChart(chartName, xName, yName, dataset, PlotOrientation.VERTICAL,
                    true, false, false);
        } else if (chartType.equals("horizontal_bar")) {
            chart = ChartFactory.createBarChart(chartName, xName, yName, dataset, PlotOrientation.HORIZONTAL,
                    true, false, false);
        } else if (chartType.equals("line")) {
            chart = ChartFactory.createLineChart(chartName, xName, yName, dataset, PlotOrientation.VERTICAL,
                    true, false, false);
        } else if (chartType.equals("vertical_bar")) {
            chart = ChartFactory.createBarChart(chartName, xName, yName, dataset, PlotOrientation.VERTICAL,
                    true, false, false);
        } else {
            PieDataset pieData = DatasetUtilities.createPieDatasetForRow(dataset, 0);

            chart = ChartFactory.createPieChart(chartName, pieData, true, false, false);
        }

        response.setContentType("image/jpeg");

        OutputStream out = response.getOutputStream();

        ChartUtilities.writeChartAsJPEG(out, chart, 400, 400);

        return mapping.findForward("/common/null.jsp");
    } catch (Exception e) {
        request.setAttribute(PageContext.EXCEPTION, e);

        return mapping.findForward("/common/error.jsp");
    }
}

From source file:net.sourceforge.javydreamercsw.validation.manager.web.component.ExecutionDashboard.java

private void init() {
    setCaption(TRANSLATOR.translate("execution.dash"));
    setHeight(100, Unit.PERCENTAGE);/*  w ww.  j  ava  2 s  .  co  m*/
    setWidth(100, Unit.PERCENTAGE);
    //Gather stats
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    extractions.forEach((e) -> {
        ExecutionStats es = new ExecutionStats(e);
        es.stats.entrySet().forEach((entry) -> {
            //This is for the whole execution
            ExecutionResultServer.getResults().forEach((er) -> {
                if (e.getTestCase() == null || e.getTestCase().getName().equals(entry.getKey())) {
                    dataset.addValue(new Double(entry.getValue().get(er.getResultName())), entry.getKey(),
                            Lookup.getDefault().lookup(InternationalizationProvider.class)
                                    .translate(er.getResultName()));
                }
            });
        });
    });
    //Build bar graph
    JFreeChart chart = ChartFactory.createBarChart(TRANSLATOR.translate("execution.progress"), // chart title
            TRANSLATOR.translate("test.case"), TRANSLATOR.translate("general.amount"), dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, false);
    setContent(new JFreeChartWrapper(chart));
}

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

/**
 * Creates a new demo instance.//from  w ww  .j  ava 2  s  .  c  o  m
 *
 * @param title  the frame title.
 */
public DualAxisDemo(final String title) {

    super(title);

    final CategoryDataset dataset1 = createDataset1();

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Dual Axis Chart", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset1, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips?
            false // URL generator?  Not required...
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);
    //        chart.getLegend().setAnchor(Legend.SOUTH);

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(new Color(0xEE, 0xEE, 0xFF));
    plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

    final CategoryDataset dataset2 = createDataset2();
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
    final ValueAxis axis2 = new NumberAxis("Secondary");
    plot.setRangeAxis(1, axis2);

    final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
    renderer2.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    plot.setRenderer(1, renderer2);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
    // OPTIONAL CUSTOMISATION COMPLETED.

    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}

From source file:com.liferay.samplestruts.struts.action.ViewChartAction.java

@Override
public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    try {//from w w  w .j a  va 2  s. c o m
        if (_log.isInfoEnabled()) {
            _log.info("execute");
        }

        String attrName = "chart_name";

        // Application scoped session attributes can be fetched from the
        // servlet directly. Portlet scoped session attributes can be
        // fetched from Sun's PortletSessionUtil.

        HttpSession session = request.getSession();

        String chartName = (String) session.getAttribute(attrName);
        //(String)_getAttribute(request, attrName);

        // Chart

        String chartType = request.getParameter("chart_type");

        CategoryDataset dataset = _getDataset();

        String xName = "Soda";
        String yName = "Votes";

        JFreeChart chart = null;

        if (chartType.equals("area")) {
            chart = ChartFactory.createAreaChart(chartName, xName, yName, dataset, PlotOrientation.VERTICAL,
                    true, false, false);
        } else if (chartType.equals("horizontal_bar")) {
            chart = ChartFactory.createBarChart(chartName, xName, yName, dataset, PlotOrientation.HORIZONTAL,
                    true, false, false);
        } else if (chartType.equals("line")) {
            chart = ChartFactory.createLineChart(chartName, xName, yName, dataset, PlotOrientation.VERTICAL,
                    true, false, false);
        } else if (chartType.equals("vertical_bar")) {
            chart = ChartFactory.createBarChart(chartName, xName, yName, dataset, PlotOrientation.VERTICAL,
                    true, false, false);
        } else {
            PieDataset pieData = DatasetUtilities.createPieDatasetForRow(dataset, 0);

            chart = ChartFactory.createPieChart(chartName, pieData, true, false, false);
        }

        response.setContentType("image/jpeg");

        OutputStream out = response.getOutputStream();

        ChartUtilities.writeChartAsJPEG(out, chart, 400, 400);

        return actionMapping.findForward("/common/null.jsp");
    } catch (Exception e) {
        request.setAttribute(PageContext.EXCEPTION, e);

        return actionMapping.findForward("/common/error.jsp");
    }
}

From source file:org.mili.jmibs.jfree.JFreeChartBarIterationObjectLoadBenchmarkSuiteResultRenderer.java

private JFreeChart createChart(String title, CategoryDataset dataset) {
    JFreeChart chart = ChartFactory.createBarChart(title, "Benchmark (Iteration/Object Loading)", "Time in ns",
            dataset, PlotOrientation.HORIZONTAL, true, true, false);
    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);/*w w  w  . j av  a  2 s. c  o  m*/
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    return chart;
}