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:org.mili.jmibs.jfree.JFreeChartBarIterationObjectLoadIntervalBenchmarkSuiteResultRenderer.java

private JFreeChart createChart(String title, CategoryDataset dataset) {
    JFreeChart chart = ChartFactory.createBarChart(title, "Benchmark (Iteration/Object Loading/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);/*from ww w .j  ava 2s. c  om*/
    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:net.imglib2.script.analysis.BarChart.java

@SuppressWarnings("rawtypes")
static private final JFreeChart createChart(final Map<? extends Number, ? extends Number> data,
        final String title, final String xLabel, final String yLabel) {
    DefaultCategoryDataset dcd = new DefaultCategoryDataset();
    for (final Map.Entry<? extends Number, ? extends Number> e : data.entrySet()) {
        dcd.addValue(e.getValue(), "", (Comparable) e.getKey());
    }//  w  w w  . j a v  a  2  s .  c om
    boolean legend = false;
    boolean tooltips = true;
    boolean urls = false;
    JFreeChart chart = ChartFactory.createBarChart(title, xLabel, yLabel, dcd, PlotOrientation.VERTICAL, legend,
            tooltips, urls);
    setBarTheme(chart);
    return chart;
}

From source file:graphs.LimitsGraphs.java

/**
 * Creates a sample chart./*from  w w  w .  j av a2 s .  co m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Limits ..", // chart title
            "Metric", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );

    // 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:Reportes.BarChart.java

public ChartPanel reporteCantidadCotizacionesSede(DefaultCategoryDataset data) {
    JFreeChart chart = ChartFactory.createBarChart("Reporte de cantidad de cotizaciones por empleado",
            "Empleado", "Cantidad", data, PlotOrientation.VERTICAL, true, true, true);

    CategoryPlot categoryP = chart.getCategoryPlot();
    BarRenderer renderer = (BarRenderer) categoryP.getRenderer();
    renderer.setMaximumBarWidth(0.35);/*  ww w  .  j a  v  a 2s .co m*/
    Color color = new Color(67, 165, 208);
    renderer.setSeriesPaint(0, color);

    ChartPanel panel = new ChartPanel(chart, true, true, true, false, false);
    panel.setSize(ancho, alto);

    return panel;
}

From source file:com.liferay.polls.web.internal.portlet.action.ViewChartMVCResourceCommand.java

@Override
protected void doServeResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws Exception {

    try {/*www.j  av a  2s. c  o  m*/
        ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);

        long questionId = ParamUtil.getLong(resourceRequest, "questionId");

        String chartType = ParamUtil.getString(resourceRequest, "chartType", "pie");
        String chartName = themeDisplay.translate("vote-results");
        String xName = themeDisplay.translate("choice");
        String yName = themeDisplay.translate("votes");

        CategoryDataset categoryDataset = PollsUtil.getVotesDataset(questionId);

        JFreeChart jFreeChat = null;

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

            jFreeChat = ChartFactory.createPieChart(chartName, pieDataset, true, false, false);
        }

        resourceResponse.setContentType(ContentTypes.IMAGE_JPEG);

        OutputStream outputStream = resourceResponse.getPortletOutputStream();

        ChartUtilities.writeChartAsJPEG(outputStream, jFreeChat, 400, 400);
    } catch (Exception e) {
        PortletSession portletSession = resourceRequest.getPortletSession();

        PortletContext portletContext = portletSession.getPortletContext();

        PortletRequestDispatcher requestDispatcher = portletContext.getRequestDispatcher("/polls/error.jsp");

        requestDispatcher.forward(resourceRequest, resourceResponse);
    }
}

From source file:com.sonyericsson.jenkins.plugins.bfa.graphs.BarChart.java

@Override
protected JFreeChart createGraph() {
    CategoryDataset dataset = createDataset();
    JFreeChart chart = ChartFactory.createBarChart(graphTitle, "", "Number of failures", dataset,
            PlotOrientation.HORIZONTAL, false, false, false);

    NumberAxis domainAxis = new NumberAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setRangeAxis(domainAxis);//from w ww . java  2s.  c  o m

    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setMaximumBarWidth(MAX_BAR_WIDTH);

    return chart;
}

From source file:org.gaixie.micrite.patrolRiverSummary.action.PatrolRiverSummaryChartAction.java

/**
 * 2D/*  w  w w . j av  a 2s.  c  o  m*/
 * @return "success"
 */
public String getBarChart() {
    CategoryDataset dca = PatrolRiverSummaryService.getCarDictionaryBarDataset(this.getQueryBean());
    chart = ChartFactory.createBarChart(getText("?"), getText(""),
            getText(""), dca, PlotOrientation.VERTICAL, true, false, false);
    BarStyle.styleOne(chart);
    this.putChartResultList(chart);
    return SUCCESS;
}

From source file:edu.wustl.cab2b.client.ui.visualization.charts.BarChart.java

protected JFreeChart createChart(Dataset dataset) {
    CategoryDataset categoryDataSet = (CategoryDataset) dataset;

    JFreeChart jFreeChart = ChartFactory.createBarChart("Bar Chart", null, "Value", categoryDataSet,
            PlotOrientation.VERTICAL, true, true, false);
    jFreeChart.setBackgroundPaint(Color.white);

    CategoryPlot categoryPlot = (CategoryPlot) jFreeChart.getPlot();
    categoryPlot.setBackgroundPaint(Color.white);
    categoryPlot.setDomainGridlinePaint(Color.white);
    categoryPlot.setRangeGridlinePaint(Color.white);

    NumberAxis numberAxis = (NumberAxis) categoryPlot.getRangeAxis();
    numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer barRenderer = (BarRenderer) categoryPlot.getRenderer();
    barRenderer.setDrawBarOutline(false);
    barRenderer.setMinimumBarLength(0.7D);
    barRenderer.setMaximumBarWidth(0.7D);
    barRenderer.setItemMargin(0.1D);//from w w w . j  a va 2 s . c o  m

    CategoryAxis categoryaxis = categoryPlot.getDomainAxis();
    categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    return jFreeChart;
}

From source file:com.modeln.build.ctrl.charts.CMnPatchCountChart.java

/**
 * Create a chart representing the number patches grouped by time interval.
 * The data passed in the hashtable is a list of the time intervals and
 * the value is the number of patch requests for each interval.
 *
 * @param  data   Hashtable cnotaining the time intervals and corresponding counts
 * @param  label  Count label/* w ww  . j a v a2s . c  om*/
 *
 * @return Bar chart representing the interval and count information
 */
public static final JFreeChart getPatchesByIntervalChart(Hashtable<CMnTimeInterval, Integer> data,
        String label) {
    JFreeChart chart = null;

    String title = "Patches per " + label;
    String nameLabel = label;
    String valueLabel = "Patches";

    // Sort the data by date
    Vector<CMnTimeInterval> intervals = new Vector<CMnTimeInterval>();
    Enumeration intervalList = data.keys();
    while (intervalList.hasMoreElements()) {
        intervals.add((CMnTimeInterval) intervalList.nextElement());
    }
    Collections.sort(intervals);

    // Populate the dataset with data
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    Iterator keyIter = intervals.iterator();
    while (keyIter.hasNext()) {
        CMnTimeInterval interval = (CMnTimeInterval) keyIter.next();
        Integer value = data.get(interval);
        dataset.addValue(value, valueLabel, interval.getName());
    }

    // Create the chart
    chart = ChartFactory.createBarChart(title, /*title*/
            nameLabel, /*categoryAxisLabel*/
            valueLabel, /*valueAxisLabel*/
            dataset, /*dataset*/
            PlotOrientation.VERTICAL, /*orientation*/
            false, /*legend*/
            false, /*tooltips*/
            false /*urls*/
    );

    // get a reference to the plot for further customization...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    //chartFormatter.formatMetricChart(plot, "min");

    // Set the chart colors
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

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

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setShadowVisible(false);
    final GradientPaint gp = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.blue);
    renderer.setSeriesPaint(0, gp);

    // Set the label orientation
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    return chart;
}

From source file:uk.ac.ed.epcc.webapp.charts.jfreechart.JFreeBarTimeChartData.java

@Override
public JFreeChart getJFreeChart() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    double counts[] = ds.getCounts();
    String legends[] = ds.getLegends();
    int max_len = 0;
    for (int i = 0; i < ds.getNumSets(); i++) {
        if (legends != null && legends.length > i) {
            dataset.addValue(new Double(counts[i]), "Series-1", legends[i]);
            int leg_len = legends[i].length();
            if (leg_len > max_len) {
                max_len = leg_len;/*from w ww.j av a 2  s .  c  o  m*/
            }
            //System.out.println(legends[i] + counts[i]);
        } else {
            dataset.addValue(new Double(counts[i]), "Series-1", Integer.toString(i));
        }
    }
    CategoryDataset data = dataset;

    JFreeChart chart = ChartFactory.createBarChart(title, null, quantity, data, PlotOrientation.VERTICAL, false, // include legends
            false, // tooltips
            false // urls
    );

    CategoryPlot categoryPlot = chart.getCategoryPlot();
    CategoryAxis axis = categoryPlot.getDomainAxis();
    if (max_len > 8 || ds.getNumSets() > 16 || (max_len * ds.getNumSets()) > 50) {
        axis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
    }
    Font tickLabelFont = axis.getTickLabelFont();
    if (ds.getNumSets() > 24) {
        axis.setTickLabelFont(tickLabelFont.deriveFont(tickLabelFont.getSize() - 2.0F));
    }
    Font labelFont = axis.getLabelFont();
    axis.setMaximumCategoryLabelLines(3);
    //axis.setLabelFont(labelFont.d);
    // axis.setLabel("Pingu"); This works so we can modify

    return chart;

}