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.jfree.chart.demo.SurveyResultsDemo.java

/**
 * Creates a chart./*from   www  .  j a  v a2  s .c  om*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createBarChart(null, // chart title
            null, // domain axis label
            null, // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            false, // include legend
            true, false);

    chart.setBackgroundPaint(Color.white);

    final TextTitle title = new TextTitle("Figure 7 | I. Resources - The site offers users relevant, "
            + "informative and educational resources");
    title.setHorizontalAlignment(HorizontalAlignment.LEFT);
    title.setBackgroundPaint(Color.red);
    title.setPaint(Color.white);

    chart.setTitle(title);
    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setOutlinePaint(null);
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePosition(CategoryAnchor.END);
    plot.setDomainGridlineStroke(new BasicStroke(0.5f));
    plot.setDomainGridlinePaint(Color.black);

    plot.setRangeGridlinesVisible(false);
    plot.clearRangeMarkers();

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setVisible(false);
    domainAxis.setCategoryMargin(0.50);

    plot.getRangeAxis().setVisible(false);

    final CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, new Color(0x9C, 0xA4, 0x4A));
    renderer.setOutlineStroke(null);
    renderer.setBaseOutlineStroke(null);

    renderer.setItemLabelsVisible(true);
    renderer.setItemLabelFont(new Font("SansSerif", Font.BOLD, 10));
    final ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.INSIDE3, TextAnchor.CENTER_RIGHT);
    renderer.setPositiveItemLabelPosition(position);

    final CategoryTextAnnotation a1 = new CategoryTextAnnotation("1. White papers are available.", "Category 1",
            0.0);
    a1.setFont(new Font("SansSerif", Font.BOLD, 12));
    a1.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    a1.setCategoryAnchor(CategoryAnchor.START);
    plot.addAnnotation(a1);

    final CategoryTextAnnotation a2 = new CategoryTextAnnotation(
            "2. White papers enhance users " + "understanding of the firm and its expertise.", "Category 2",
            0.0);
    a2.setFont(new Font("SansSerif", Font.PLAIN, 12));
    a2.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    a2.setCategoryAnchor(CategoryAnchor.START);
    plot.addAnnotation(a2);

    final CategoryTextAnnotation a3 = new CategoryTextAnnotation(
            "3. White papers are relevant to " + "the firm's prospects and clients.", "Category 3", 0.0);
    a3.setFont(new Font("SansSerif", Font.PLAIN, 12));
    a3.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    a3.setCategoryAnchor(CategoryAnchor.START);
    plot.addAnnotation(a3);

    final CategoryTextAnnotation a4 = new CategoryTextAnnotation(
            "4. White papers are relevant to " + "the firm's positioning.", "Category 4", 0.0);
    a4.setFont(new Font("SansSerif", Font.PLAIN, 12));
    a4.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    a4.setCategoryAnchor(CategoryAnchor.START);
    plot.addAnnotation(a4);

    final CategoryTextAnnotation a5 = new CategoryTextAnnotation("5. Case studies are available.", "Category 5",
            0.0);
    a5.setFont(new Font("SansSerif", Font.BOLD, 12));
    a5.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    a5.setCategoryAnchor(CategoryAnchor.START);
    plot.addAnnotation(a5);

    final CategoryTextAnnotation a6 = new CategoryTextAnnotation(
            "6. Case studies enhance users " + "understanding of the firm and its expertise.", "Category 6",
            0.0);
    a6.setFont(new Font("SansSerif", Font.PLAIN, 12));
    a6.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    a6.setCategoryAnchor(CategoryAnchor.START);
    plot.addAnnotation(a6);

    final CategoryTextAnnotation a7 = new CategoryTextAnnotation(
            "7. Case studies are relevant to " + "the firm's prospects and clients.", "Category 7", 0.0);
    a7.setFont(new Font("SansSerif", Font.PLAIN, 12));
    a7.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    a7.setCategoryAnchor(CategoryAnchor.START);
    plot.addAnnotation(a7);

    final CategoryTextAnnotation a8 = new CategoryTextAnnotation(
            "8. White papers are relevant to the firm's positioning.", "Category 8", 0.0);
    a8.setFont(new Font("SansSerif", Font.PLAIN, 12));
    a8.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    a8.setCategoryAnchor(CategoryAnchor.START);
    plot.addAnnotation(a8);

    final CategoryTextAnnotation a9 = new CategoryTextAnnotation("9. Case studies are available.", "Category 9",
            0.0);
    a9.setFont(new Font("SansSerif", Font.BOLD, 12));
    a9.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    a9.setCategoryAnchor(CategoryAnchor.START);
    plot.addAnnotation(a9);

    final CategoryTextAnnotation a10 = new CategoryTextAnnotation(
            "10. Case studies enhance users " + "understanding of the firm and its expertise.", "Category 10",
            0.0);
    a10.setFont(new Font("SansSerif", Font.PLAIN, 12));
    a10.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    a10.setCategoryAnchor(CategoryAnchor.START);
    plot.addAnnotation(a10);

    final CategoryTextAnnotation a11 = new CategoryTextAnnotation(
            "11. Case studies are relevant " + "to the firm's prospects and clients.", "Category 11", 0.0);
    a11.setFont(new Font("SansSerif", Font.PLAIN, 12));
    a11.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    a11.setCategoryAnchor(CategoryAnchor.START);
    plot.addAnnotation(a11);

    final CategoryTextAnnotation a12 = new CategoryTextAnnotation(
            "12. White papers are relevant to the firm's positioning.", "Category 12", 0.0);
    a12.setFont(new Font("SansSerif", Font.PLAIN, 12));
    a12.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    a12.setCategoryAnchor(CategoryAnchor.START);
    plot.addAnnotation(a12);

    final CategoryTextAnnotation a13 = new CategoryTextAnnotation(
            "13. Users can easily access " + "resources based on viewer interest.", "Category 13", 0.0);
    a13.setFont(new Font("SansSerif", Font.BOLD, 12));
    a13.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    a13.setCategoryAnchor(CategoryAnchor.START);
    plot.addAnnotation(a13);

    final CategoryTextAnnotation a14 = new CategoryTextAnnotation(
            "14. Access to additional hyperlinks enhances users's ability to find relevant " + "information.",
            "Category 14", 0.0);
    a14.setFont(new Font("SansSerif", Font.BOLD, 12));
    a14.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    a14.setCategoryAnchor(CategoryAnchor.START);
    plot.addAnnotation(a14);

    final CategoryTextAnnotation a15 = new CategoryTextAnnotation("15. OVERALL EFFECTIVENESS.", "Overall", 0.0);
    a15.setFont(new Font("SansSerif", Font.BOLD, 12));
    a15.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    a15.setCategoryAnchor(CategoryAnchor.START);
    plot.addAnnotation(a15);

    return chart;

}

From source file:com.vectorprint.report.jfree.ChartBuilder.java

private void prepareChart(Dataset data, CHARTTYPE type) throws VectorPrintException {
    switch (type) {
    case AREA:/*from w ww  .j a va  2  s  .  c  o m*/
        chart = ChartFactory.createAreaChart(title, categoryLabel, valueLabel, null, getOrientation(), legend,
                tooltips, urls);
    case LINE:
        if (chart == null) {
            chart = ChartFactory.createLineChart(title, categoryLabel, valueLabel, null, getOrientation(),
                    legend, tooltips, urls);
        }
    case LINE3D:
        if (chart == null) {
            chart = ChartFactory.createLineChart3D(title, categoryLabel, valueLabel, null, getOrientation(),
                    legend, tooltips, urls);
        }
    case BAR:
        if (chart == null) {
            chart = ChartFactory.createBarChart(title, categoryLabel, valueLabel, null, getOrientation(),
                    legend, tooltips, urls);
        }
    case BAR3D:
        if (chart == null) {
            chart = ChartFactory.createBarChart3D(title, categoryLabel, valueLabel, null, getOrientation(),
                    legend, tooltips, urls);
        }

        if (data instanceof CategoryDataset) {
            CategoryDataset cd = (CategoryDataset) data;

            chart.getCategoryPlot().setDataset(cd);
        } else {
            throw new VectorPrintException("you should use CategoryDataset for this chart");
        }

        break;

    case PIE:
        chart = ChartFactory.createPieChart(title, null, legend, tooltips, urls);
    case PIE3D:
        if (chart == null) {
            chart = ChartFactory.createPieChart3D(title, null, legend, tooltips, urls);
        }

        if (data instanceof PieDataset) {
            PieDataset pd = (PieDataset) data;
            PiePlot pp = (PiePlot) chart.getPlot();

            pp.setDataset(pd);
        } else {
            throw new VectorPrintException("you should use PieDataset for this chart");
        }

        break;

    case XYLINE:
        chart = ChartFactory.createXYLineChart(title, categoryLabel, valueLabel, null, getOrientation(), legend,
                tooltips, urls);
    case XYAREA:
        if (chart == null) {
            chart = ChartFactory.createXYAreaChart(title, categoryLabel, valueLabel, null, getOrientation(),
                    legend, tooltips, urls);
        }

        if (data instanceof XYDataset) {
            XYDataset xy = (XYDataset) data;

            chart.getXYPlot().setDataset(xy);
        } else {
            throw new VectorPrintException("you should use XYDataset for this chart");
        }

        break;

    case TIME:
        chart = ChartFactory.createTimeSeriesChart(title, categoryLabel, valueLabel, null, legend, tooltips,
                urls);

        if (data instanceof TimeSeriesCollection) {
            TimeSeriesCollection xy = (TimeSeriesCollection) data;

            chart.getXYPlot().setDataset(xy);
        } else {
            throw new VectorPrintException("you should use TimeSeriesCollection for this chart");
        }

        break;

    default:
        throw new VectorPrintException("unsupported chart");
    }

    chart.setAntiAlias(true);
    chart.setTextAntiAlias(true);
}

From source file:tdunnick.jphineas.console.queue.Charts.java

/**
 * Creates the bar chart.  Set the X-axis font small enough to accommodate
 * dates and tidy up the bars.//from   w ww . jav a 2 s.  c o  m
 * @param title for the chart
 * @param dataset for the chart
 * @return the chart
 */
private JFreeChart createBarChart(String title, CategoryDataset dataset) {
    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart(title, null, // domain axis label
            "Messages", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );
    CategoryPlot plot = chart.getCategoryPlot();
    plot.getDomainAxis().setTickLabelFont(new Font("Arial", Font.BOLD, 9));
    BarRenderer renderer = (BarRenderer) chart.getCategoryPlot().getRenderer();
    renderer.setItemMargin(0.01);
    renderer.setDrawBarOutline(true);
    renderer.setShadowVisible(false);
    return chart;
}

From source file:org.drugis.mtc.gui.results.ResultsComponentFactory.java

public static ChartPanel buildRankProbabilityChart(final ConsistencyWrapper<?> wrapper) {
    CategoryDataset dataset = new RankProbabilityDataset(wrapper.getRankProbabilities());
    JFreeChart rankChart = ChartFactory.createBarChart("Rank Probability", "Treatment", "Probability", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    final ChartPanel chartPanel = new ChartPanel(rankChart);
    return chartPanel;
}

From source file:org.pentaho.chart.plugin.jfreechart.chart.bar.JFreeBarChartGenerator.java

/**
 * Creates the JFree chart based on the chart document, data provided and
 * type of chart expected./*from   w ww  .  j  a v  a  2  s  . c om*/
 * </p>
 * @param chartDocContext  Chart documument context for the current chart.
 * @param data             Data for the current chart.
 * @param chartType        Bar chart type (interval, stacked, default/basic)
 * @return Returns the JFree chart object (created by the method)
 */
public JFreeChart createChart(final ChartDocumentContext chartDocContext, final ChartTableModel data,
        final String chartType) {
    final ChartDocument chartDocument = chartDocContext.getChartDocument();
    final String title = getTitle(chartDocument);
    final String valueCategoryLabel = getValueCategoryLabel(chartDocument);
    final String valueAxisLabel = getValueAxisLabel(chartDocument);
    final PlotOrientation orientation = getPlotOrientation(chartDocument);
    final boolean legend = getShowLegend(chartDocument);
    final boolean toolTips = getShowToolTips(chartDocument);

    DefaultCategoryDataset categoryDataset = null;
    final DefaultIntervalCategoryDataset intervalCategoryDataset = null;

    if (JFreeBarChartTypes.INTERVAL.equalsIgnoreCase(chartType)) {
        logger.error(Messages.getErrorString("JFreeBarChartGenerator.INFO_INTERVAL_CHART_NOT_SUPPORTED")); //$NON-NLS-1$
    } else {
        categoryDataset = datasetGeneratorFactory.createDefaultCategoryDataset(chartDocContext, data);
        if (categoryDataset == null) {
            logger.error(Messages.getErrorString("JFreeChartFactoryEngine.ERROR_0001_DATASET_IS_NULL")); //$NON-NLS-1$
            return null;
        }
    }

    final JFreeChart chart;
    if (JFreeBarChartTypes.STACKED.equalsIgnoreCase(chartType)) {
        chart = ChartFactory.createStackedBarChart(title, valueCategoryLabel, valueAxisLabel, categoryDataset,
                orientation, legend, toolTips, false);
    } else if (JFreeBarChartTypes.INTERVAL.equalsIgnoreCase(chartType)) {
        chart = ChartFactory.createBarChart(title, valueCategoryLabel, valueAxisLabel, intervalCategoryDataset,
                orientation, legend, toolTips, false);
    } else if (JFreeBarChartTypes.WATERFALL.equalsIgnoreCase(chartType)) {
        chart = ChartFactory.createBarChart(title, valueCategoryLabel, valueAxisLabel, intervalCategoryDataset,
                orientation, legend, toolTips, false);
    } else {
        chart = ChartFactory.createBarChart(title, valueCategoryLabel, valueAxisLabel, categoryDataset,
                orientation, legend, toolTips, false);
    }

    final ChartElement[] seriesElements = chartDocument.getRootElement()
            .findChildrenByName(ChartElement.TAG_NAME_SERIES);
    final CategoryPlot categoryPlot = chart.getCategoryPlot();
    if (seriesElements != null && categoryPlot != null) {
        setSeriesAttributes(seriesElements, data, categoryPlot);
        setAxisMargins(chartDocument, categoryPlot);
    }

    return chart;
}

From source file:reports.util.BarChart2Scriptlet.java

/**
 *
 *//*  w ww  .j a va 2s .  c o  m*/
public void afterReportInit() throws JRScriptletException {

    JFreeChart jfreechart = ChartFactory.createBarChart("Bar Chart Demo", // chart title
            "States", // X Label
            "Sell Amount", // Y Label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );

    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = jfreechart.getCategoryPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setDomainGridlinePaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.white);

    LegendTitle legendtitle = (LegendTitle) jfreechart.getSubtitle(0);
    legendtitle.setPosition(RectangleEdge.RIGHT);
    legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D));

    IntervalMarker intervalmarker = new IntervalMarker(200D, 250D);
    intervalmarker.setLabel("Target Range");
    intervalmarker.setLabelFont(new Font("SansSerif", 2, 11));
    intervalmarker.setLabelAnchor(RectangleAnchor.LEFT);
    intervalmarker.setLabelTextAnchor(TextAnchor.CENTER_LEFT);
    intervalmarker.setPaint(new Color(222, 222, 255, 128));
    categoryplot.addRangeMarker(intervalmarker, Layer.BACKGROUND);

    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setDrawBarOutline(false);
    barrenderer.setItemMargin(0.10000000000000001D);

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

    barrenderer.setSeriesPaint(0, gradientpaint);
    barrenderer.setSeriesPaint(1, gradientpaint1);
    barrenderer.setSeriesPaint(2, gradientpaint2);

    barrenderer.setItemLabelGenerator(new LabelGenerator());
    barrenderer.setItemLabelsVisible(true);
    //ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE12, TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, -1.5707963267948966D);
    //barrenderer.setPositiveItemLabelPosition(itemlabelposition);

    ItemLabelPosition itemlabelposition1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
            TextAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, -1.5707963267948966D);
    barrenderer.setPositiveItemLabelPositionFallback(itemlabelposition1);

    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    /*   */
    this.setVariableValue("Chart", new JCommonDrawableRenderer(jfreechart));
}

From source file:view.tabtables.EmulationTablesDrawer.java

protected void graphsInitialize() {
    JPanel panel;/*from  w w  w  .  j  a  v a2  s  .c o m*/
    JFreeChart chart;

    frequencyDataset = new DefaultCategoryDataset();
    chart = ChartFactory.createBarChart("Frequency", // chart title
            "Marking", // domain axis label
            "Value", // range axis label
            frequencyDataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips?
            false // URLs?
    );
    CategoryPlot plot = chart.getCategoryPlot();
    CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setSeriesItemLabelsVisible(0, Boolean.TRUE);
    panel = new ChartPanel(chart, false);
    add(panel);

    timeAvgDataset = new DefaultCategoryDataset();
    chart = ChartFactory.createBarChart("Avg Time", // chart title
            "Marking", // domain axis label
            "Value", // range axis label
            timeAvgDataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips?
            false // URLs?
    );
    plot = chart.getCategoryPlot();
    renderer = plot.getRenderer();
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setSeriesItemLabelsVisible(0, Boolean.TRUE);
    panel = new ChartPanel(chart, false);
    add(panel);

    timeAvgReturnDataset = new DefaultCategoryDataset();
    chart = ChartFactory.createBarChart("Avg Return Time", // chart title
            "Marking", // domain axis label
            "Value", // range axis label
            timeAvgReturnDataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips?
            false // URLs?
    );
    plot = chart.getCategoryPlot();
    renderer = plot.getRenderer();
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setSeriesItemLabelsVisible(0, Boolean.TRUE);
    panel = new ChartPanel(chart, false);
    add(panel);

    probabilityDataset = new DefaultCategoryDataset();
    chart = ChartFactory.createBarChart("Probability", // chart title
            "Marking", // domain axis label
            "Value", // range axis label
            probabilityDataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips?
            false // URLs?
    );
    plot = chart.getCategoryPlot();
    renderer = plot.getRenderer();
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setSeriesItemLabelsVisible(0, Boolean.TRUE);
    panel = new ChartPanel(chart, false);
    add(panel);
}

From source file:sturesy.voting.gui.VotingEvaluationPanelUI.java

private JFreeChart createChart(final CategoryDataset dataset, String questiontext, Color background,
        boolean showAnswers, List<Integer> correctAnswers, boolean showPercent) {
    String valueAxisLabel = Localize.getString(showPercent ? "label.votes.percent" : "label.votes.absolute");

    final JFreeChart chart = ChartFactory.createBarChart(questiontext, Localize.getString("label.answers"),
            valueAxisLabel, dataset, PlotOrientation.VERTICAL, false, true, false);

    chart.setBackgroundPaint(background);

    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setNoDataMessage("NO DATA!");

    final CategoryItemRenderer renderer = new AnswersBarRenderer(showAnswers, correctAnswers);

    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelFont(renderer.getBaseItemLabelFont().deriveFont(16.0f));

    final ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER,
            TextAnchor.CENTER, 45.0);//from w w  w .  j av a2 s .  com

    renderer.setBasePositiveItemLabelPosition(p);

    plot.setRenderer(renderer);

    // 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);
    double upperrange = rangeAxis.getRange().getUpperBound();

    if (showPercent) {
        renderer.setBaseItemLabelGenerator(new AppendPercentRenderer());
        rangeAxis.setRange(new Range(0, upperrange > 100 ? 100 : upperrange), false, false);
    } else {
        renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    }

    plot.getDomainAxis().setMaximumCategoryLabelLines(5);
    return chart;

}

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

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

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart(CHART_TITLE, // chart title
            "Activity", // domain axis label
            "Rate", // 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(new Color(255, 255, 180));

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(BACKGROUND_PAINT);
    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);

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

    final StandardLegend legend = (StandardLegend) chart.getLegend();
    legend.setBackgroundPaint(Color.orange);
    legend.setOutlinePaint(Color.orange);

    // activate word wrapping when legend is vertical.
    legend.setPreferredWidth(125);

    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

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

/**
 * Creates a sample chart./*from   w  ww  . j av  a  2 s.  c om*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
protected JFreeChart createChart(CategoryDataset dataset) {

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

    chart.setBackgroundPaint(Color.white);

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

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

    // disable bar outlines...
    LayeredBarRenderer renderer = new LayeredBarRenderer();
    renderer.setDrawBarOutline(false);
    plot.setRenderer(renderer);

    // for this renderer, we need to draw the first series last...
    plot.setRowRenderingOrder(SortOrder.DESCENDING);

    // 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));
    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);
    renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());
    setCategorySummary(dataset);
    return chart;

}