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:ws.moor.bt.gui.charts.DownloadRatePerPeer.java

private JFreeChart createChart() {

    JFreeChart chart = ChartFactory.createBarChart("Top 20 Download Rates", "Remote IP", "KB/s",
            createDataset(), PlotOrientation.VERTICAL, false, false, false);
    chart.setBackgroundPaint(Color.white);

    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

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

    return chart;
}

From source file:graficarordenamiento.Graficador.java

public void crearGrafico() {
    // Creando el Grafico
    chart = ChartFactory.createBarChart("Grfico de barras", null, null, dataset, PlotOrientation.VERTICAL,
            false, false, false);//from   ww w .  ja va2  s. c o  m

    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.WHITE, 700, 0, Color.BLACK.brighter(), false));
    chart.setBackgroundImageAlpha(0.5f);
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setNoDataMessage("NO DATA!");
    plot.setRangeGridlinePaint(Color.red);
    plot.setBackgroundPaint(new GradientPaint(0, 0, Color.LIGHT_GRAY, 0, 100, Color.darkGray));
    plot.setBackgroundImageAlpha(0.5f);
    //plot.setDomainGridlinesVisible(true);

    BarRenderer rend = (BarRenderer) plot.getRenderer();

    final ItemLabelPosition e = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER,
            TextAnchor.CENTER, 45.0);

    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));

    rend.setSeriesPaint(0, gp0);
    rend.setSeriesPaint(1, gp1);
    rend.setSeriesPaint(2, gp2);
    plot.setRenderer(rend);

    // change the margin at the top of the range axis...
    final ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLowerMargin(0.15);
    rangeAxis.setUpperMargin(0.15);

    // set up gradient paints for series...

}

From source file:org.epsilonlabs.workflow.execution.example.GraphOutput.java

public GraphOutput(String appname, String graphname, String x, String y) {
    super(appname);
    barChart = ChartFactory.createBarChart(graphname, x, y, dataset, PlotOrientation.VERTICAL, false, true,
            false);//from   w  ww  .ja  v  a  2 s .c  o  m

    ChartPanel chartPanel = new ChartPanel(barChart);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    int width = new Double(screenSize.getWidth()).intValue() - 100;
    chartPanel.setMaximumDrawHeight(500);
    chartPanel.setMaximumDrawWidth(width);
    chartPanel.setPreferredSize(new java.awt.Dimension(width, 500));
    setContentPane(chartPanel);

    Font font = new Font("Dialog", Font.PLAIN, 15);
    barChart.getCategoryPlot().getDomainAxis().setTickLabelFont(font);
    barChart.getCategoryPlot().setColumnRenderingOrder(SortOrder.DESCENDING);

}

From source file:edu.jhuapl.graphs.jfreechart.JFreeChartStackedBarGraphSource.java

@Override
public JFreeChart createChart(String title, String xLabel, String yLabel, CategoryDataset dataset,
        boolean legend, boolean graphToolTip) {
    PlotOrientation orientation = getParam(PLOT_ORIENTATION, PlotOrientation.class, DEFAULT_PLOT_ORIENTATION);
    JFreeChart result = ChartFactory.createBarChart(title, xLabel, yLabel, dataset, orientation, legend,
            graphToolTip, false);/* www . jav  a 2  s.  c o  m*/
    StackedBarRenderer renderer = new CategoryStackedBarGraphRenderer(data);

    renderer.setShadowVisible(false);
    renderer.setBarPainter(new CategoryGraphBarPainter(data));
    result.getCategoryPlot().setRenderer(renderer);

    return result;
}

From source file:jasmine.imaging.core.JasmineCorrelationGraph.java

public void processData() {
    DefaultCategoryDataset series = new DefaultCategoryDataset();

    for (int i = 0; i < observed.length; i++) {
        StatisticsSolver obs = observed[i];
        double correlation = obs.getCorrelationWith(expected);
        if (!Double.isNaN(correlation)) {
            series.addValue(correlation, "series1", names[i]);
        }/*w  w  w .  j a v a 2s  .  c om*/
        System.out.println(names[i] + ": " + correlation);
    }

    myChart = ChartFactory.createBarChart(null, "Features", "Pearson Correlation", series,
            PlotOrientation.VERTICAL, false, false, false);

}

From source file:josejamilena.pfc.analizador.GraficoPorSGBD.java

public GraficoPorSGBD(final String sgbd, final String script) throws ClassNotFoundException, SQLException {

    Map<String, String> res = new TreeMap<String, String>();
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    Statement stmt = null;//from   ww w  . ja v  a 2  s  .co  m
    ResultSet rs = null;
    String consulta = "select tiempo, fecha from estadisticas where tipo=\'" + script + "\' and host_sgbd=\'"
            + sgbd + "\'";
    stmt = App.conn.createStatement();
    rs = stmt.executeQuery(consulta);
    while (rs.next()) {
        res.put(rs.getString(2), rs.getString(1));
    }
    rs.close();
    stmt.close();

    Iterator it = res.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry pairs = (Map.Entry) it.next();
        dataset.setValue(Double.parseDouble(pairs.getValue().toString()), script, pairs.getKey().toString());
    }

    JFreeChart chart = ChartFactory.createBarChart(sgbd, // chart title
            "Hora", // domain axis label
            "Duracin (milisegundos)", // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, false, // include legend
            true, false);

    CategoryPlot plot = chart.getCategoryPlot();
    chart.setBackgroundPaint(Color.white);
    plot.setOutlinePaint(Color.black);
    ChartPanel chartPanel = new ChartPanel(chart);
    JScrollPane scrollPane = new JScrollPane();
    scrollPane.getViewport().add((new JPanel()).add(chartPanel));
    setContentPane(scrollPane);
}

From source file:josejamilena.pfc.analizador.GraficoPorCliente.java

public GraficoPorCliente(final String cliente, final String script)
        throws ClassNotFoundException, SQLException {

    Map<String, String> res = new TreeMap<String, String>();
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    Statement stmt = null;//from ww  w  . j  a  v  a  2  s.co  m
    ResultSet rs = null;
    String consulta = "select tiempo, fecha from estadisticas where tipo=\'" + script + "\' and host_cliente=\'"
            + cliente + "\'";
    stmt = App.conn.createStatement();
    rs = stmt.executeQuery(consulta);
    while (rs.next()) {
        res.put(rs.getString(2), rs.getString(1));
    }
    rs.close();
    stmt.close();

    Iterator it = res.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry pairs = (Map.Entry) it.next();
        dataset.setValue(Double.parseDouble(pairs.getValue().toString()), script, pairs.getKey().toString());
    }

    JFreeChart chart = ChartFactory.createBarChart(cliente, // chart title
            "Hora", // domain axis label
            "Duracin (milisegundos)", // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, false, // include legend
            true, false);

    CategoryPlot plot = chart.getCategoryPlot();
    chart.setBackgroundPaint(Color.white);
    plot.setOutlinePaint(Color.black);
    ChartPanel chartPanel = new ChartPanel(chart);
    JScrollPane scrollPane = new JScrollPane();
    scrollPane.getViewport().add((new JPanel()).add(chartPanel));
    setContentPane(scrollPane);
}

From source file:org.ow2.clif.jenkins.chart.QuantileDistributionChart.java

@Override
protected JFreeChart createChart() {
    JFreeChart chart = ChartFactory.createBarChart(getBasicTitle(),
            Messages.QuantileDistributionChart_PercentageOfRequests(),
            Messages.QuantileDistributionChart_ResponseTime(), data, PlotOrientation.VERTICAL, true, true,
            false);/*from ww  w .j  a v  a  2s .  c om*/
    chart.getCategoryPlot().setRangeGridlinesVisible(true);
    chart.getCategoryPlot().setDomainGridlinesVisible(true);
    return chart;
}

From source file:com.csc.GUI.ProfileGUIPanel.java

private JFreeChart createBarChart(final CategoryDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Expenses Statistics", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/*from ww  w  .  j av 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));
    // OPTIONAL CUSTOMISATION COMPLETED.
    return chart;
}

From source file:josejamilena.pfc.analizador.GraficoPorScript.java

public GraficoPorScript(final String hostCliente, final String hostSgbd)
        throws ClassNotFoundException, SQLException {

    Map<String, String> res = new TreeMap<String, String>();
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    Statement stmt = null;//  w w w  .  ja  va  2 s . c  om
    ResultSet rs = null;
    String consulta = "select tiempo, fecha from estadisticas where host_cliente=\'" + hostCliente
            + "\' and host_sgbd=\'" + hostSgbd + "\'";
    stmt = App.conn.createStatement();
    rs = stmt.executeQuery(consulta);
    while (rs.next()) {
        res.put(rs.getString(2), rs.getString(1));
    }
    rs.close();
    stmt.close();

    Iterator it = res.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry pairs = (Map.Entry) it.next();
        dataset.setValue(Double.parseDouble(pairs.getValue().toString()), hostCliente,
                pairs.getKey().toString());
    }

    JFreeChart chart = ChartFactory.createBarChart(hostCliente + " / " + hostSgbd, // chart title
            "Hora", // domain axis label
            "Duracin (milisegundos)", // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, false, // include legend
            true, false);

    CategoryPlot plot = chart.getCategoryPlot();
    chart.setBackgroundPaint(Color.white);
    plot.setOutlinePaint(Color.black);
    ChartPanel chartPanel = new ChartPanel(chart);
    JScrollPane scrollPane = new JScrollPane();
    scrollPane.getViewport().add((new JPanel()).add(chartPanel));
    setContentPane(scrollPane);
}