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.rapidminer.gui.plotter.charts.ParetoChartPlotter.java

private JFreeChart createChart() {
    if (data.getItemCount() > 0) {
        // get cumulative percentages
        KeyedValues cumulative = DataUtilities.getCumulativePercentages(data);

        CategoryDataset categoryDataset = DatasetUtilities.createCategoryDataset(
                "Count for " + this.dataTable.getColumnName(this.countColumn) + " = " + countValue, data);

        // create the chart...
        final JFreeChart chart = ChartFactory.createBarChart(null, // chart title
                this.dataTable.getColumnName(this.groupByColumn), // domain axis label
                "Count", // range axis label
                categoryDataset, // data
                PlotOrientation.VERTICAL, true, // include legend
                true, false);/*from  ww w . jav  a  2 s . c  om*/

        // set the background color for the chart...
        chart.setBackgroundPaint(Color.WHITE);

        // get a reference to the plot for further customization...
        CategoryPlot plot = chart.getCategoryPlot();

        CategoryAxis domainAxis = plot.getDomainAxis();
        domainAxis.setLowerMargin(0.02);
        domainAxis.setUpperMargin(0.02);
        domainAxis.setLabelFont(LABEL_FONT_BOLD);
        domainAxis.setTickLabelFont(LABEL_FONT);

        // set the range axis to display integers only...
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits(Locale.US));
        rangeAxis.setLabelFont(LABEL_FONT_BOLD);
        rangeAxis.setTickLabelFont(LABEL_FONT);

        // second data set (cumulative percentages)
        CategoryDataset dataset2 = DatasetUtilities.createCategoryDataset("Cumulative (Percent)", cumulative);

        LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
        renderer2.setSeriesPaint(0, SwingTools.VERY_DARK_BLUE.darker());

        NumberAxis axis2 = new NumberAxis("Percent of " + countValue);
        axis2.setNumberFormatOverride(NumberFormat.getPercentInstance());
        axis2.setLabelFont(LABEL_FONT_BOLD);
        axis2.setTickLabelFont(LABEL_FONT);

        plot.setRangeAxis(1, axis2);
        plot.setDataset(1, dataset2);
        plot.setRenderer(1, renderer2);
        plot.mapDatasetToRangeAxis(1, 1);

        axis2.setTickUnit(new NumberTickUnit(0.1));

        // show grid lines
        plot.setRangeGridlinesVisible(true);

        // bring cumulative line to front
        plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

        if (isLabelRotating()) {
            domainAxis.setTickLabelsVisible(true);
            domainAxis.setCategoryLabelPositions(
                    CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0d));
        }

        return chart;
    } else {
        return null;
    }
}

From source file:com.jolbox.benchmark.BenchmarkMain.java

/**
 * @param title /*from   www  .  j  av a2s.  c o  m*/
 * @param filename 
 * @param results 
 */
private static void plotBarGraph(String title, String filename, long[] results) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (ConnectionPoolType poolType : ConnectionPoolType.values()) {
        dataset.setValue(results[poolType.ordinal()], "ms", poolType);
    }
    JFreeChart chart = ChartFactory.createBarChart(title, "Connection Pool", "Time (ms)", dataset,
            PlotOrientation.VERTICAL, false, true, false);
    try {
        String fname = System.getProperty("java.io.tmpdir") + File.separator + filename;
        ChartUtilities.saveChartAsPNG(new File(fname), chart, 1024, 768);
        System.out.println("******* Saved chart to: " + fname);
    } catch (IOException e) {
        e.printStackTrace();
        System.err.println("Problem occurred creating chart.");
    }
}

From source file:gg.view.overview.IncomeExpensesTopComponent.java

/** Displays the total income vs expenses for the current month */
public void displayData() {
    log.info("Income vs Expenses graph computed and displayed");

    // Display hourglass cursor
    Utilities.changeCursorWaitStatus(true);

    // Create a dataset (the dataset will contain the plotted values)
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    // Create an empty chart
    JFreeChart chart = ChartFactory.createBarChart("", // chart title
            "", // x axis label
            NbBundle.getMessage(IncomeExpensesTopComponent.class, "IncomeExpensesTopComponent.Amount"), // y axis label
            dataset, // data displayed in the chart
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips
            false // urls
    );/*from  ww w. j  a v a 2 s . co m*/

    // Update the chart color
    chart.setBackgroundPaint(jPanelIncomeExpenses.getBackground());
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);

    // Set the orientation of the categories on the domain axis (X axis)
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD);

    // Set the range axis (Y axis) to display integers only
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // Set the bar renderer
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setMaximumBarWidth(0.1);

    GradientPaint gradientPaint = new GradientPaint(0.0f, 0.0f, new Color(49, 106, 196), 0.0f, 0.0f,
            Color.LIGHT_GRAY);
    renderer.setSeriesPaint(0, gradientPaint);

    // Create a period for the current month
    LocalDate today = new LocalDate();
    Period currentMonth = new Period(Periods.getAdjustedStartDate(today, PeriodType.MONTH),
            Periods.getAdjustedEndDate(today, PeriodType.MONTH), PeriodType.MONTH);

    // Fill the dataset
    List<Currency> currencies = Wallet.getInstance().getActiveCurrencies();
    for (Currency currency : currencies) {
        // Filter on the currency and on the current month
        SearchCriteria searchCriteria = new SearchCriteria(currency, null, currentMonth, null, null, null,
                false);

        // Get income
        BigDecimal currencyIncome = Datamodel.getIncome(searchCriteria);
        currencyIncome = currencyIncome.setScale(2, RoundingMode.HALF_EVEN);

        // Get expenses
        BigDecimal currencyExpenses = Datamodel.getExpenses(searchCriteria).abs();
        currencyExpenses = currencyExpenses.setScale(2, RoundingMode.HALF_EVEN);

        // Plot income and expenses for the current month and for the current currency on the chart
        dataset.addValue(currencyIncome, currency.getName(),
                NbBundle.getMessage(IncomeExpensesTopComponent.class, "IncomeExpensesTopComponent.Income",
                        new Object[] { currency }));

        dataset.addValue(currencyExpenses, currency.getName(),
                NbBundle.getMessage(IncomeExpensesTopComponent.class, "IncomeExpensesTopComponent.Expenses",
                        new Object[] { currency }));
    }

    // Create the chart panel that contains the chart
    ChartPanel chartPanel = new ChartPanel(chart);

    // Display the chart
    jPanelIncomeExpenses.removeAll();
    jPanelIncomeExpenses.add(chartPanel, BorderLayout.CENTER);

    // Display the normal cursor
    Utilities.changeCursorWaitStatus(false);
}

From source file:edu.ucla.stat.SOCR.chart.demo.BarChartDemo7.java

protected JFreeChart createLegend(CategoryDataset dataset) {

    //  JFreeChart chart = ChartFactory.createAreaChart(
    JFreeChart chart = ChartFactory.createBarChart(chartTitle, // chart title
            domainLabel, // domain axis label
            rangeLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );/*from  w w  w  .  ja v  a  2s . com*/

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = chart.getCategoryPlot();

    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setItemMargin(0.10);

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray);
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray);
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray);
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);
    renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());
    return chart;

}

From source file:com.opensourcestrategies.crmsfa.reports.JFreeCrmsfaCharts.java

/**
 * Open Cases snapshot.  Description at http://www.opentaps.org/docs/index.php/CRMSFA_Dashboard
 * Note that this counts all the cases in the system for now.
 *///from w  ww  .  ja  v a 2s  . c om
public static String createOpenCasesChart(Delegator delegator, Locale locale)
        throws GenericEntityException, IOException {
    Map uiLabelMap = UtilMessage.getUiLabels(locale);

    // create the dataset
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    // get all case statuses that are not "closed" (this is dynamic because statuses may be added at run time)
    List<GenericValue> statuses = ReportHelper.findCasesStagesForDashboardReporting(delegator);

    // Report number of cases for each status
    for (GenericValue status : statuses) {
        String statusId = status.getString("statusId");
        long count = delegator.findCountByCondition("CustRequest",
                EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, statusId), null);
        dataset.addValue(count, "", (String) status.get("description", locale));
    }

    // set up the chart
    JFreeChart chart = ChartFactory.createBarChart((String) uiLabelMap.get("CrmOpenCases"), // chart title
            null, // domain axis label
            null, // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );
    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setPadding(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    // get the bar renderer to put effects on the bars
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false); // disable bar outlines

    // set up gradient paint on bar
    final GradientPaint gp = new GradientPaint(0.0f, 0.0f, new Color(246, 227, 206), 0.0f, 0.0f,
            new Color(204, 153, 102));
    renderer.setSeriesPaint(0, gp);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // tilt the category labels so they fit
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    // save as a png and return the file name
    return ServletUtilities.saveChartAsPNG(chart, 360, 300, null);
}

From source file:unalcol.termites.boxplots.SucessfulRatesGlobal.java

private static JFreeChart createChart(CategoryDataset categorydataset, ArrayList<Double> pf) {
    JFreeChart jfreechart = ChartFactory.createBarChart("Success Rates - " + getTitle(pf), "", "",
            categorydataset, PlotOrientation.VERTICAL, true, true, false);
    jfreechart.getTitle().setFont(new Font("Sans-Serif", Font.PLAIN, 18));
    jfreechart.setBackgroundPaint(new Color(221, 223, 238));
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.white);
    categoryplot.setDomainGridlinePaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.gray);
    categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    BarRenderer renderer = (BarRenderer) categoryplot.getRenderer();
    //categoryplot.setBackgroundPaint(new Color(221, 223, 238));

    renderer.setSeriesPaint(0, new Color(130, 165, 70));
    renderer.setSeriesPaint(1, new Color(220, 165, 70));
    renderer.setSeriesPaint(4, new Color(255, 165, 70));
    renderer.setDrawBarOutline(false);/*  w w w . j av  a2s  . co m*/
    renderer.setShadowVisible(false);
    // renderer.setMaximumBarWidth(1);
    renderer.setGradientPaintTransformer(null);
    renderer.setDefaultBarPainter(new StandardBarPainter());

    categoryplot.setRenderer(renderer);

    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setUpperMargin(0.25D);
    CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer();
    categoryitemrenderer.setBaseItemLabelsVisible(true);
    categoryitemrenderer.setBaseItemLabelGenerator(new LabelGenerator(null));
    numberaxis.setRange(0, 100);
    //numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());

    Font font = new Font("SansSerif", Font.ROMAN_BASELINE, 12);
    numberaxis.setTickLabelFont(font);
    CategoryAxis axisd = categoryplot.getDomainAxis();
    ValueAxis axisr = categoryplot.getRangeAxis();
    axisd.setTickLabelFont(font);
    axisr.setTickLabelFont(font);

    final ChartPanel chartPanel = new ChartPanel(jfreechart);
    chartPanel.setPreferredSize(new java.awt.Dimension(650, 370));

    FileOutputStream output;
    try {
        output = new FileOutputStream("successGlobalRates" + pf + ".jpg");
        ChartUtilities.writeChartAsJPEG(output, 1.0f, jfreechart, 650, 370, null);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(MessagesSent1.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(MessagesSent1.class.getName()).log(Level.SEVERE, null, ex);
    }
    return jfreechart;
}

From source file:monitor.StatsWindow.java

private void jButtonRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRefreshActionPerformed

    DefaultCategoryDataset dateset = new DefaultCategoryDataset();
    dateset.setValue(Window.getIndeksWordsInSettingsWindow()[0], "", "1");
    dateset.setValue(Window.getIndeksWordsInSettingsWindow()[1], "", "2");
    dateset.setValue(Window.getIndeksWordsInSettingsWindow()[2], "", "3");
    dateset.setValue(Window.getIndeksWordsInSettingsWindow()[3], "", "4");
    dateset.setValue(Window.getIndeksWordsInSettingsWindow()[4], "", "5");

    DefaultCategoryDataset dateset2 = new DefaultCategoryDataset();
    dateset2.setValue(Window.getIndeksWordsInSettingsWindow2()[0], "", "1");
    dateset2.setValue(Window.getIndeksWordsInSettingsWindow2()[1], "", "2");
    dateset2.setValue(Window.getIndeksWordsInSettingsWindow2()[2], "", "3");
    dateset2.setValue(Window.getIndeksWordsInSettingsWindow2()[3], "", "4");
    dateset2.setValue(Window.getIndeksWordsInSettingsWindow2()[4], "", "5");

    JFreeChart chart = ChartFactory.createBarChart("Prefiks counts diagram", "", "", dateset,
            PlotOrientation.HORIZONTAL, false, false, false);
    CategoryPlot catPlot = chart.getCategoryPlot();
    catPlot.setRangeGridlinePaint(Color.BLACK);

    JFreeChart chart2 = ChartFactory.createBarChart("Sufiks counts diagram", "", "", dateset2,
            PlotOrientation.HORIZONTAL, false, false, false);
    CategoryPlot catPlot2 = chart2.getCategoryPlot();
    catPlot2.setRangeGridlinePaint(Color.BLACK);

    ChartPanel chartPanel = new ChartPanel(chart);
    jPanelDiagram.removeAll();//from   www .  j a v  a  2s .  c  om
    jPanelDiagram.add(chartPanel, BorderLayout.CENTER);
    jPanelDiagram.validate();

    ChartPanel chartPanel2 = new ChartPanel(chart2);
    jPanelDiagram2.removeAll();
    jPanelDiagram2.add(chartPanel2, BorderLayout.CENTER);
    jPanelDiagram2.validate();

    jTextAreaNGramWords.setText(Window.getWordsInSettingsWindow());

    jTextAreaSufiksWords.setText(Window.getWordsInSettingsWindow2());

}

From source file:vista.DestinosMasConsultados.java

public void iniciarGraficos(CategoryDataset dataset) {
    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Paises mas consultados", // chart title
            "Paises", // domain axis label
            "Cantidad de consultas", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/*  w  w  w  .  ja  v a 2  s .  c  o m*/

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // set up gradient paints for series...
    final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray);
    final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray);
    final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray);
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    ChartPanel chartFinal = new ChartPanel(chart);
    chartFinal.setSize(new Dimension(600, 400));

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(panelDestinosMasConsultados);
    panelDestinosMasConsultados.setLayout(jPanel1Layout);
    jPanel1Layout
            .setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup().addGap(0, 0, 0).addComponent(chartFinal)
                            .addContainerGap(0, Short.MAX_VALUE)));
    jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup().addGap(0, 0, 0).addComponent(chartFinal)
                    .addContainerGap(0, Short.MAX_VALUE)));

}

From source file:org.usip.osp.graphs.GraphServer.java

public static JFreeChart getDemoChart() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.addValue(10.0, "S1", "C1"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(4.0, "S1", "C2"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(15.0, "S1", "C3"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(14.0, "S1", "C4"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(-5.0, "S2", "C1"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(-7.0, "S2", "C2"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(14.0, "S2", "C3"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(-3.0, "S2", "C4"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(6.0, "S3", "C1"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(17.0, "S3", "C2"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(-12.0, "S3", "C3"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(7.0, "S3", "C4"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(7.0, "S4", "C1"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(15.0, "S4", "C2"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(11.0, "S4", "C3"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(0.0, "S4", "C4"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(-8.0, "S5", "C1"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(-6.0, "S5", "C2"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(10.0, "S5", "C3"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(-9.0, "S5", "C4"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(9.0, "S6", "C1"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(8.0, "S6", "C2"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(null, "S6", "C3"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(6.0, "S6", "C4"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(-10.0, "S7", "C1"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(9.0, "S7", "C2"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(7.0, "S7", "C3"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(7.0, "S7", "C4"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(11.0, "S8", "C1"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(13.0, "S8", "C2"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(9.0, "S8", "C3"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(9.0, "S8", "C4"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(-3.0, "S9", "C1"); //$NON-NLS-1$ //$NON-NLS-2$
    dataset.addValue(7.0, "S9", "C2");
    dataset.addValue(11.0, "S9", "C3");
    dataset.addValue(-10.0, "S9", "C4");
    JFreeChart chart = ChartFactory.createBarChart("Bar Chart", "Category", "Value", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    return chart;

}

From source file:com.jolbox.benchmark.BenchmarkLaunch.java

/**
 * @param title //from  w  ww . j a  v a2s .  c o  m
 * @param filename 
 * @param results 
 * @throws IOException 
 */
private static void plotBarGraph(String title, String filename, long[] results) throws IOException {
    String fname = System.getProperty("java.io.tmpdir") + File.separator + filename;
    PrintWriter out = new PrintWriter(new FileWriter(fname + ".txt"));

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (ConnectionPoolType poolType : ConnectionPoolType.values()) {
        dataset.setValue(results[poolType.ordinal()], "ms", poolType);
        out.println(results[poolType.ordinal()] + "," + poolType);
    }
    out.close();
    JFreeChart chart = ChartFactory.createBarChart(title, "Connection Pool", "Time (ms)", dataset,
            PlotOrientation.VERTICAL, false, true, false);
    try {
        ChartUtilities.saveChartAsPNG(new File(fname), chart, 1024, 768);
        System.out.println("******* Saved chart to: " + fname);
    } catch (IOException e) {
        e.printStackTrace();
        System.err.println("Problem occurred creating chart.");
    }
}