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:graphs.ResultsGraphs.java

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

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Mashup Language Sentiment Algorithm Performance ", // chart title
            "Performance 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:com.manydesigns.portofino.chart.ChartBarGenerator.java

protected JFreeChart createChart(ChartDefinition chartDefinition, CategoryDataset dataset,
        PlotOrientation plotOrientation) {
    return ChartFactory.createBarChart(chartDefinition.getName(), chartDefinition.getXAxisName(),
            chartDefinition.getYAxisName(), dataset, plotOrientation, true, true, true);
}

From source file:gui.images.ClassHubsPanel.java

/**
 * Sets the distribution of point types to be shown in the column chart.
 *
 * @param pTypes Float array representing the point type distribution.
 */// www . ja v  a 2 s.  c om
public void setPointTypeDistribution(float[] pTypes) {
    DefaultCategoryDataset hDistDataset = new DefaultCategoryDataset();
    hDistDataset.addValue(pTypes[0], "Examples", "safe");
    hDistDataset.addValue(pTypes[1], "Examples", "borderline");
    hDistDataset.addValue(pTypes[2], "Examples", "rare");
    hDistDataset.addValue(pTypes[3], "Examples", "outlier");
    JFreeChart chart = ChartFactory.createBarChart("Point Type Distribution", "", "", hDistDataset,
            PlotOrientation.VERTICAL, false, true, false);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(316, 240));
    final CategoryPlot plot = chart.getCategoryPlot();
    CategoryItemRenderer renderer = new CustomRenderer();
    plot.setRenderer(renderer);
    pointTypePanel.removeAll();
    pointTypePanel.add(chartPanel);
    pointTypePanel.revalidate();
    pointTypePanel.repaint();
}

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

private static JFreeChart createChart() {
    JFreeChart jfreechart = ChartFactory.createBarChart("Dual Axis Chart", "Category", "Value",
            createDataset1(), PlotOrientation.VERTICAL, false, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(new Color(238, 238, 255));
    categoryplot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
    CategoryDataset categorydataset = createDataset2();
    categoryplot.setDataset(1, categorydataset);
    categoryplot.mapDatasetToRangeAxis(1, 1);
    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
    NumberAxis numberaxis = new NumberAxis("Secondary");
    categoryplot.setRangeAxis(1, numberaxis);
    LineAndShapeRenderer lineandshaperenderer = new LineAndShapeRenderer();
    lineandshaperenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    categoryplot.setRenderer(1, lineandshaperenderer);
    categoryplot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    LegendTitle legendtitle = new LegendTitle(categoryplot.getRenderer(0));
    legendtitle.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
    legendtitle.setFrame(new BlockBorder());
    LegendTitle legendtitle1 = new LegendTitle(categoryplot.getRenderer(1));
    legendtitle1.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
    legendtitle1.setFrame(new BlockBorder());
    BlockContainer blockcontainer = new BlockContainer(new BorderArrangement());
    blockcontainer.add(legendtitle, RectangleEdge.LEFT);
    blockcontainer.add(legendtitle1, RectangleEdge.RIGHT);
    blockcontainer.add(new EmptyBlock(2000D, 0.0D));
    CompositeTitle compositetitle = new CompositeTitle(blockcontainer);
    compositetitle.setPosition(RectangleEdge.BOTTOM);
    jfreechart.addSubtitle(compositetitle);
    return jfreechart;
}

From source file:org.neo4j.bench.chart.GenerateOpsPerSecChart.java

private void generateChart() throws Exception {
    DefaultCategoryDataset dataset = generateDataset();
    JFreeChart chart = ChartFactory.createBarChart("Performance chart", "Bench case", "Operations per sec",
            dataset, PlotOrientation.VERTICAL, true, true, false);

    Dimension dimensions = new Dimension(1600, 900);
    File chartFile = new File(outputFilename);
    if (alarm) {//www .  j a  v  a2s .co m
        chart.setBackgroundPaint(Color.RED);
    }
    ChartUtilities.saveChartAsPNG(chartFile, chart, (int) dimensions.getWidth(), (int) dimensions.getHeight());
}

From source file:org.openmrs.module.usagestatistics668.web.view.chart.AccessVisitChartView.java

/**
 * create bar chart for visit data/*  ww  w . j a v  a  2s . co  m*/
 * @param model model build for view
 * @param request
 * @return JFREEChart for viewing encounter data
 */
@Override
protected JFreeChart createChart(Map<String, Object> model, HttpServletRequest request) {
    AccessVisitService svc = Context.getService(AccessVisitService.class);

    List<Object[]> data = svc.getMostViewedVisit(getFromDate(), getUntilDate(), getUsageFilter(),
            getMaxResults());
    String[] categories = new String[data.size()];
    int[] count = new int[data.size()];
    for (int i = 0; i < categories.length; i++) {
        categories[i] = String.valueOf(data.get(i)[0]);
        count[i] = ((BigInteger) data.get(i)[1]).intValue();
    }

    String yAxisLabel = ContextProvider.getMessage("usagestatistics668.summary.count");
    String xAxisLabel = ContextProvider.getMessage("usagestatistics668.summary.visit");
    String seriesView = ContextProvider.getMessage("usagestatistics668.summary.any");
    if (getUsageFilter() == ActionCriteria.CREATED) {
        seriesView = ContextProvider.getMessage("usagestatistics668.summary.created");
    } else if (getUsageFilter() == ActionCriteria.UPDATED) {
        seriesView = ContextProvider.getMessage("usagestatistics668.summary.updated");
    } else if (getUsageFilter() == ActionCriteria.VIEWED) {
        seriesView = ContextProvider.getMessage("usagestatistics668.summary.viewed");
    } else if (getUsageFilter() == ActionCriteria.VOIDED) {
        seriesView = ContextProvider.getMessage("usagestatistics668.summary.voided");
    } else if (getUsageFilter() == ActionCriteria.UNVOIDED) {
        seriesView = ContextProvider.getMessage("usagestatistics668.summary.unvoided");
    }

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (int c = 0; c < data.size(); c++) {
        dataset.addValue(count[c], seriesView, (categories != null) ? categories[c] : (c + ""));
    }

    JFreeChart chart = ChartFactory.createBarChart(null, // Chart title
            xAxisLabel, // Domain axis label
            yAxisLabel, // Range axis label
            dataset, // Data
            PlotOrientation.VERTICAL, // Orientation
            true, // Include legend
            false, // Tooltips?
            false // URLs?
    );

    return chart;
}

From source file:org.simbrain.plot.barchart.BarChartGui.java

/**
 * Initializes frame./*from  w ww . j a v  a  2 s.co m*/
 */
@Override
public void postAddInit() {

    // Generate the graph
    chart = ChartFactory.createBarChart("Bar Chart", // chart title
            "Bar", // domain axis label
            "Value", // range axis label
            this.getWorkspaceComponent().getModel().getDataset(), // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips?
            false // URLs?

    );
    chartPanel.setChart(chart);
    chart.getCategoryPlot().getRangeAxis().setAutoRange(getWorkspaceComponent().getModel().isAutoRange());
    if (!getWorkspaceComponent().getModel().isAutoRange()) {
        chart.getCategoryPlot().getRangeAxis().setRange(getWorkspaceComponent().getModel().getLowerBound(),
                getWorkspaceComponent().getModel().getUpperBound());
    }

    // Add a chart setting listener
    getWorkspaceComponent().getModel().addChartSettingsListener(new ChartSettingsListener() {

        // TODO: Explore parameters in
        // chart, chart.getCategoryPlot(),
        // chart.getCategoryPlot().getRenderer(), chartPanel..
        public void chartSettingsUpdated() {

            // Update colors
            chart.getCategoryPlot().getRenderer().setSeriesPaint(0,
                    getWorkspaceComponent().getModel().getBarColor());

            // Update auto-range
            chart.getCategoryPlot().getRangeAxis()
                    .setAutoRange(getWorkspaceComponent().getModel().isAutoRange());

            // Update ranges
            if (!getWorkspaceComponent().getModel().isAutoRange()) {
                chart.getCategoryPlot().getRangeAxis().setRange(
                        getWorkspaceComponent().getModel().getLowerBound(),
                        getWorkspaceComponent().getModel().getUpperBound());
            }
        }
    });

    // Fire the chart listener to update settings
    getWorkspaceComponent().getModel().fireSettingsChanged();
}

From source file:fitmon.Chart.java

/**
 * Creates a sample chart./*w  ww .  j a  v  a 2  s  .c  o m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo", // chart title
            "Category", // 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:net.sf.jooreports.web.samples.SalesReportGenerator.java

private RenderedImage createChart(Object model) {
    List lines = (List) ((Map) model).get("lines");
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (Iterator it = lines.iterator(); it.hasNext();) {
        ReportLine line = (ReportLine) it.next();
        dataset.addValue(line.getValue(), "sales", line.getMonth());
    }/*from  ww  w. ja va  2s.co  m*/
    JFreeChart chart = ChartFactory.createBarChart("Monthly Sales", "Month", "Sales", dataset,
            PlotOrientation.VERTICAL, false, false, false);
    chart.setTitle((String) null);
    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = chart.getCategoryPlot();
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    GradientPaint paint = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    renderer.setSeriesPaint(0, paint);
    BufferedImage image = chart.createBufferedImage(400, 300);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    try {
        ImageIO.write(image, "png", outputStream);
    } catch (IOException ioException) {
        throw new RuntimeException("should never happen: " + ioException.getMessage());
    }
    return image;
}

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

/**
 * Creates an internal frame.//  w  w w .  ja v a 2s . co m
 * 
 * @return An internal frame.
 */
private JInternalFrame createFrame1() {
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.addValue(34.0, "Series 1", "Category 1");
    dataset.addValue(23.0, "Series 1", "Category 2");
    dataset.addValue(54.0, "Series 1", "Category 3");
    final JFreeChart chart = ChartFactory.createBarChart("Bar Chart", "Category", "Series", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(200, 100));
    final JInternalFrame frame = new JInternalFrame("Frame 1", true);
    frame.getContentPane().add(chartPanel);
    return frame;

}