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:mrmc.chart.BarGraph.java

/**
 * Constructs the chart//from  ww  w .j a  v  a  2 s. c  om
 * 
 * @param dataset Representation of x-y data
 * @param title Title of chart
 * @param xaxis Label for x-axis
 * @param yaxis Label for y-axis
 * @return The chart
 */
private JFreeChart createChart(final CategoryDataset dataset, String title, String xaxis, String yaxis) {

    final JFreeChart chart = ChartFactory.createBarChart(title, xaxis, yaxis, dataset, PlotOrientation.VERTICAL,
            true, true, false);
    return chart;

}

From source file:gui.BarChart.java

/**
 * Zusammenbauen des Diagrammes./*from   w w  w  .  j  a v  a2s.c  om*/
 * 
 * @return diagramm
 */
private JFreeChart createChart() {

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("", // berschrift
            label_x_axis, // x label
            label_y_axis, // y label
            dataset, // datenstze
            PlotOrientation.VERTICAL, // vertikale balken
            true, // mit legende
            true, // mit tooltips
            false // URLs???
    );

    // Layoutanpassungen im Folgende:

    // allg. Hintergrundfarbe
    chart.setBackgroundPaint(Color.white);

    // Referenz auf Zeichnung:
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setNoDataMessage("NO DATA!");

    // aussehen des eigentlichen diagrammes:
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);

    // skaleneinteilung:
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setUpperMargin(0.1);

    // kategorien renderer einstellungen verndern:                
    final CategoryItemRenderer categories = plot.getRenderer();
    // casten in bar renderer:
    final BarRenderer bars = (BarRenderer) categories;

    // werte im diagramm anzeigen:
    categories.setLabelGenerator(new StandardCategoryLabelGenerator());
    categories.setItemLabelsVisible(true);
    final ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER,
            TextAnchor.CENTER, -Math.PI / 6);

    categories.setPositiveItemLabelPosition(p);
    categories.setNegativeItemLabelPosition(p);

    plot.setRenderer(categories);

    // farbverlauf der serien 1 und 2
    final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, new Color(127, 127, 255), 0.0f, 0.0f,
            new Color(127, 127, 127));
    final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, new Color(255, 127, 127), 0.0f, 0.0f,
            new Color(127, 127, 127));
    bars.setSeriesPaint(0, gp0);
    bars.setSeriesPaint(1, gp1);
    // keine umrandung der balken
    bars.setDrawBarOutline(false);

    // abstand der zahlen vom balken
    bars.setItemLabelAnchorOffset(13);

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

    return chart;

}

From source file:com.att.aro.main.TraceOverviewPanel.java

/**
 * Initializes the Main panel and its various components.
 *///from  w  ww.j  av a  2 s  .  co  m
private void initialize() {
    JFreeChart chart = ChartFactory.createBarChart(rb.getString("overview.traceoverview.title"), null, null,
            createDataset(null), PlotOrientation.HORIZONTAL, false, true, false);
    chart.setBackgroundPaint(this.getBackground());
    chart.getTitle().setFont(AROUIManager.HEADER_FONT);

    this.plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.gray);
    plot.setRangeGridlinePaint(Color.gray);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

    CategoryAxis valueRangeAxis = plot.getDomainAxis();
    valueRangeAxis.setMaximumCategoryLabelWidthRatio(1.0f);
    valueRangeAxis.setMaximumCategoryLabelLines(2);
    valueRangeAxis.setLabelFont(AROUIManager.LABEL_FONT);
    valueRangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setLabel(rb.getString("analysisresults.percentile"));
    rangeAxis.setRange(0.0, 100.0);
    rangeAxis.setTickUnit(new NumberTickUnit(10));
    rangeAxis.setLabelFont(AROUIManager.LABEL_FONT);
    rangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT);

    BarRenderer renderer = new StackedBarRenderer();
    renderer.setBasePaint(AROUIManager.CHART_BAR_COLOR);
    renderer.setAutoPopulateSeriesPaint(false);
    renderer.setBaseItemLabelGenerator(new PercentLabelGenerator());
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelPaint(Color.black);

    // Make second bar in stack invisible
    renderer.setSeriesItemLabelsVisible(1, false);
    renderer.setSeriesPaint(1, new Color(0, 0, 0, 0));

    ItemLabelPosition insideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE3,
            TextAnchor.CENTER_RIGHT);
    renderer.setBasePositiveItemLabelPosition(insideItemlabelposition);

    ItemLabelPosition outsideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3,
            TextAnchor.CENTER_LEFT);
    renderer.setPositiveItemLabelPositionFallback(outsideItemlabelposition);

    renderer.setBarPainter(new StandardBarPainter());
    renderer.setShadowVisible(false);
    renderer.setMaximumBarWidth(BAR_WIDTH_PERCENT);
    renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() {
        @Override
        public String generateToolTip(CategoryDataset arg0, int arg1, int arg2) {
            String traceInfo = "";
            switch (arg2) {
            case TRACE_AVERAGE:
                traceInfo = rb.getString("tooltip.traceAnalysis.avg");
                break;
            case TRACE_ENERGY:
                traceInfo = rb.getString("tooltip.traceAnalysis.engy");
                break;
            case TRACE_OVERHEAD:
                traceInfo = rb.getString("tooltip.traceAnalysis.ovrhd");
                break;
            }

            return traceInfo;
        }
    });

    plot.setRenderer(renderer);
    plot.getDomainAxis().setMaximumCategoryLabelLines(2);

    ChartPanel chartPanel = new ChartPanel(chart, WIDTH, HEIGHT, ChartPanel.DEFAULT_MINIMUM_DRAW_WIDTH + 100,
            100, ChartPanel.DEFAULT_MAXIMUM_DRAW_WIDTH, ChartPanel.DEFAULT_MAXIMUM_DRAW_HEIGHT, USER_BUFFER,
            PROPERTIES, COPY, SAVE, PRINT, ZOOM, TOOL_TIPS);
    chartPanel.setDomainZoomable(false);
    chartPanel.setRangeZoomable(false);
    this.add(chartPanel, BorderLayout.CENTER);
}

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

/**
 * Creates a chart.//www  . j a  va2 s  .c o m
 * 
 * @param dataset  the dataset.
 * 
 * @return A chart.
 */
protected JFreeChart createChart(final CategoryDataset dataset) {
    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart(chartTitle, // chart title
            domainLabel, // domain axis label
            rangeLabel, // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            !legendPanelOn, // include legend
            true, false);

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

    plot.getRenderer().setSeriesPaint(0, new Color(0, 0, 255));
    plot.getRenderer().setSeriesPaint(1, new Color(75, 75, 255));
    plot.getRenderer().setSeriesPaint(2, new Color(150, 150, 255));

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

    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());
    // NumberAxis hna = rangeAxis;
    // MarkerAxisBand band = new MarkerAxisBand(hna, 2.0, 2.0, 2.0, 2.0,
    //     new Font("SansSerif", Font.PLAIN, 9));

    //        IntervalMarker m1 = new IntervalMarker(0.0, 33.0, "Low", Color.gray,
    //            new BasicStroke(0.5f), Color.green, 0.75f);
    //        IntervalMarker m2 = new IntervalMarker(33.0, 66.0, "Medium", Color.gray,
    //            new BasicStroke(0.5f), Color.orange, 0.75f);
    //        IntervalMarker m3 = new IntervalMarker(66.0, 100.0, "High", Color.gray,
    //            new BasicStroke(0.5f), Color.red, 0.75f);
    //        band.addMarker(m1);
    //        band.addMarker(m2);
    //        band.addMarker(m3);
    //        hna.setMarkerBand(band);
    // OPTIONAL CUSTOMISATION COMPLETED.

    setCategorySummary(dataset);
    return chart;
}

From source file:org.amanzi.splash.chart.Charts.java

/**
 * This method creates a chart.//from   ww  w . jav a 2 s  .co  m
 * 
 * @param dataset. dataset provides the data to be displayed in the chart. The parameter is
 *        provided by the 'createDataset()' method.
 * @return A chart.
 */
public static JFreeChart createBarChart(DefaultCategoryDataset dataset) {

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

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

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

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

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    renderer.setSeriesPaint(0, gp0);

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

From source file:org.matsim.core.utils.charts.BarChart.java

private JFreeChart createChart(final String title, final String categoryAxisLabel, final String valueAxisLabel,
        final CategoryDataset dataset) {
    return ChartFactory.createBarChart(title, categoryAxisLabel, valueAxisLabel, dataset,
            PlotOrientation.VERTICAL, true, // legend?
            false, // tooltips?
            false // URLs?
    );//from  www  . j a  v  a 2 s  . c  o m
}

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createBarChart("Mouseover Demo 1", "Category", "Value",
            categorydataset, PlotOrientation.VERTICAL, true, true, false);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setDomainGridlinesVisible(true);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    MyBarRenderer mybarrenderer = new MyBarRenderer();
    mybarrenderer.setDrawBarOutline(true);
    categoryplot.setRenderer(mybarrenderer);
    ChartUtilities.applyCurrentTheme(jfreechart);
    GradientPaint gradientpaint = new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, new Color(0, 0, 64));
    GradientPaint gradientpaint1 = new GradientPaint(0.0F, 0.0F, Color.green, 0.0F, 0.0F, new Color(0, 64, 0));
    GradientPaint gradientpaint2 = new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, new Color(64, 0, 0));
    mybarrenderer.setSeriesPaint(0, gradientpaint);
    mybarrenderer.setSeriesPaint(1, gradientpaint1);
    mybarrenderer.setSeriesPaint(2, gradientpaint2);
    return jfreechart;
}

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

@Override
public JFreeChart createChart(final int nbr) {
    String title = this.getChartTitle() + ", Iteration: " + this.iteration_;
    this.chart_ = ChartFactory.createBarChart(title, "Hour", "Volumes [veh/h]", this.dataset0,
            PlotOrientation.VERTICAL, true, // legend?
            true, // tooltips?
            false // URLs?
    );/*from  www  .j a  va  2  s  .co m*/
    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();
    renderer.setSeriesOutlinePaint(0, Color.black);
    renderer.setSeriesOutlinePaint(1, Color.black);
    renderer.setSeriesPaint(0, Color.getHSBColor((float) 0.62, (float) 0.56, (float) 0.93));
    // Color.orange gives a dirty yellow!
    renderer.setSeriesPaint(1, Color.getHSBColor((float) 0.1, (float) 0.79, (float) 0.89));
    renderer.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator());
    renderer.setSeriesToolTipGenerator(1, 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);
    // TRRE:  plot.setDataset(1, this.dataset1);
    plot.mapDatasetToRangeAxis(1, 1);

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

    /*  TRRE: 
    final ValueAxis axis2 = new NumberAxis("Signed Rel. Error [%]");
    plot.setRangeAxis(1, axis2);
            
    final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
    renderer2.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator());
    renderer2.setSeriesShape(0, new Rectangle2D.Double(-1.5, -1.5, 3.0, 3.0));
    renderer2.setSeriesPaint(0, Color.black);
    renderer2.setBaseStroke(new BasicStroke(2.5f));
    plot.setRenderer(1, renderer2);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    */

    return this.chart_;
}

From source file:org.owasp.jbrofuzz.graph.canvas.ResponseSizeChart.java

public ChartPanel getPlotCanvas() {

    final JFreeChart chart = ChartFactory.createBarChart("JBroFuzz Response Size Bar Chart", // chart title
            "File Name", // domain axis label
            "Response Size (bytes)", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips?
            true // URLs?
    );//from   www  .  ja  v  a 2s . c  o m

    final Plot plot = chart.getPlot();
    plot.setBackgroundImage(ImageCreator.IMG_OWASP_MED.getImage());
    plot.setBackgroundImageAlignment(Align.TOP_RIGHT);

    final CategoryItemRenderer renderer = chart.getCategoryPlot().getRenderer();
    renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());

    return new ChartPanel(chart);

}

From source file:com.att.aro.main.ProperSessionTerminationPanel.java

/**
 * Initializes the Panel for Proper Session Termination plot.
 *//*w ww  . j  a  v  a2  s  .c o m*/
private void initialize() {
    JFreeChart chart = ChartFactory.createBarChart(rb.getString("overview.sessionoverview.title"), null, null,
            createDataset(null), PlotOrientation.HORIZONTAL, false, false, false);
    chart.setBackgroundPaint(this.getBackground());
    chart.getTitle().setFont(AROUIManager.HEADER_FONT);

    this.plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.gray);
    plot.setRangeGridlinePaint(Color.gray);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setMaximumCategoryLabelWidthRatio(1.0f);
    domainAxis.setMaximumCategoryLabelLines(2);
    domainAxis.setLabelFont(AROUIManager.LABEL_FONT);
    domainAxis.setTickLabelFont(AROUIManager.LABEL_FONT);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setLabel(rb.getString("analysisresults.percentage"));
    rangeAxis.setRange(0.0, 100.0);
    rangeAxis.setTickUnit(new NumberTickUnit(10));
    rangeAxis.setLabelFont(AROUIManager.LABEL_FONT);
    rangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT);

    BarRenderer renderer = new StackedBarRenderer();
    renderer.setBasePaint(AROUIManager.CHART_BAR_COLOR);
    renderer.setAutoPopulateSeriesPaint(false);
    renderer.setBaseItemLabelGenerator(new PercentLabelGenerator());
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelPaint(Color.black);

    // Make second bar in stack invisible
    renderer.setSeriesItemLabelsVisible(1, false);
    renderer.setSeriesPaint(1, new Color(0, 0, 0, 0));

    ItemLabelPosition insideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE3,
            TextAnchor.CENTER_RIGHT);
    renderer.setBasePositiveItemLabelPosition(insideItemlabelposition);

    ItemLabelPosition outsideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3,
            TextAnchor.CENTER_LEFT);
    renderer.setPositiveItemLabelPositionFallback(outsideItemlabelposition);

    renderer.setBarPainter(new StandardBarPainter());
    renderer.setShadowVisible(false);
    renderer.setMaximumBarWidth(BAR_WIDTH_PERCENT);

    renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() {
        @Override
        public String generateToolTip(CategoryDataset arg0, int arg1, int arg2) {
            String sessionInfo = "";
            switch (arg2) {
            case SESSION_TERMINATION:
                sessionInfo = rb.getString("tooltip.sessionTermination");
                break;
            case SESSION_TIGHT_CONN:
                sessionInfo = rb.getString("tooltip.sessionTightConn");
                break;
            case SESSION_BURST:
                sessionInfo = rb.getString("tooltip.sessionBurst");
                break;
            case SESSION_LONG_BURST:
                sessionInfo = rb.getString("tooltip.sessionLongBurst");
                break;
            }

            return sessionInfo;
        }
    });

    plot.setRenderer(renderer);
    plot.getDomainAxis().setMaximumCategoryLabelLines(2);

    ChartPanel chartPanel = new ChartPanel(chart, WIDTH, HEIGHT, ChartPanel.DEFAULT_MINIMUM_DRAW_WIDTH + 100,
            100, ChartPanel.DEFAULT_MAXIMUM_DRAW_WIDTH, ChartPanel.DEFAULT_MAXIMUM_DRAW_HEIGHT, USER_BUFFER,
            PROPERTIES, COPY, SAVE, PRINT, ZOOM, TOOL_TIPS);

    chartPanel.setDomainZoomable(false);
    chartPanel.setRangeZoomable(false);
    this.add(chartPanel, BorderLayout.CENTER);
}