Example usage for org.jfree.chart.title TextTitle setBackgroundPaint

List of usage examples for org.jfree.chart.title TextTitle setBackgroundPaint

Introduction

In this page you can find the example usage for org.jfree.chart.title TextTitle setBackgroundPaint.

Prototype

public void setBackgroundPaint(Paint paint) 

Source Link

Document

Sets the background paint and sends a TitleChangeEvent to all registered listeners.

Usage

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createBarChart("Bar Chart Demo 9", null, "Value", categorydataset,
            PlotOrientation.VERTICAL, false, true, false);
    TextTitle texttitle = jfreechart.getTitle();
    texttitle.setBorder(0.0D, 0.0D, 1.0D, 0.0D);
    texttitle.setBackgroundPaint(new GradientPaint(0.0F, 0.0F, Color.red, 350F, 0.0F, Color.white, true));
    texttitle.setExpandToFitSpace(true);
    jfreechart.setBackgroundPaint(new GradientPaint(0.0F, 0.0F, Color.yellow, 350F, 0.0F, Color.white, true));
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setNoDataMessage("NO DATA!");
    categoryplot.setBackgroundPaint(null);
    categoryplot.setInsets(new RectangleInsets(10D, 5D, 5D, 5D));
    categoryplot.setOutlinePaint(Color.black);
    categoryplot.setRangeGridlinePaint(Color.gray);
    categoryplot.setRangeGridlineStroke(new BasicStroke(1.0F));
    Paint apaint[] = createPaint();
    CustomBarRenderer custombarrenderer = new CustomBarRenderer(apaint);
    custombarrenderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_HORIZONTAL));
    categoryplot.setRenderer(custombarrenderer);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setRange(0.0D, 800D);//  www .  j  ava  2  s.c o m
    numberaxis.setTickMarkPaint(Color.black);
    return jfreechart;
}

From source file:org.eobjects.datacleaner.util.ChartUtils.java

public static void applyStyles(JFreeChart chart) {
    TextTitle title = chart.getTitle();
    if (title != null) {
        title.setFont(WidgetUtils.FONT_HEADER1);
        title.setBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHTEST);
    }/*w ww.ja  v  a 2  s .  com*/

    for (int i = 0; i < chart.getSubtitleCount(); i++) {
        Title subtitle = chart.getSubtitle(i);
        if (subtitle instanceof TextTitle) {
            ((TextTitle) subtitle).setFont(WidgetUtils.FONT_NORMAL);
        }
    }

    LegendTitle legend = chart.getLegend();
    if (legend != null) {
        legend.setItemFont(WidgetUtils.FONT_SMALL);
    }

    // transparent background
    chart.setBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHTEST);
    chart.setBorderVisible(false);

    final Plot plot = chart.getPlot();
    plot.setInsets(new RectangleInsets(UnitType.ABSOLUTE, 0d, 0d, 0d, 0d));
    plot.setBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHTEST);
    plot.setOutlinePaint(WidgetUtils.BG_COLOR_BRIGHTEST);
    plot.setOutlineVisible(true);

    if (plot instanceof PiePlot) {
        // tweaks for pie charts
        final PiePlot piePlot = (PiePlot) plot;
        piePlot.setBaseSectionOutlinePaint(WidgetUtils.BG_COLOR_DARK);
        piePlot.setBaseSectionOutlineStroke(normalStroke);
        piePlot.setLabelFont(WidgetUtils.FONT_SMALL);
        piePlot.setLabelBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHT);
        piePlot.setLabelOutlineStroke(normalStroke);
        piePlot.setLabelPaint(WidgetUtils.BG_COLOR_DARK);
        piePlot.setSectionOutlinesVisible(false);
        piePlot.setLabelLinkStyle(PieLabelLinkStyle.QUAD_CURVE);
    } else if (plot instanceof CategoryPlot) {
        // tweaks for bar charts
        final CategoryPlot categoryPlot = (CategoryPlot) plot;

        int columnCount = categoryPlot.getDataset().getColumnCount();
        if (columnCount > 1) {
            categoryPlot.setDomainGridlinesVisible(true);
        } else {
            categoryPlot.setDomainGridlinesVisible(false);
        }
        categoryPlot.setDomainGridlinePaint(WidgetUtils.BG_COLOR_DARK);
        categoryPlot.setDomainGridlinePosition(CategoryAnchor.END);

        categoryPlot.getDomainAxis().setLabelFont(WidgetUtils.FONT_SMALL);
        categoryPlot.getDomainAxis().setTickLabelFont(WidgetUtils.FONT_SMALL);
        categoryPlot.getRangeAxis().setLabelFont(WidgetUtils.FONT_SMALL);
        categoryPlot.getRangeAxis().setTickLabelFont(WidgetUtils.FONT_SMALL);
        categoryPlot.setDrawingSupplier(new DCDrawingSupplier());

        final CategoryItemRenderer renderer = categoryPlot.getRenderer();
        renderer.setBaseOutlinePaint(WidgetUtils.BG_COLOR_DARK);
        renderer.setBaseOutlineStroke(wideStroke);

        if (renderer instanceof BarRenderer) {
            BarRenderer barRenderer = (BarRenderer) renderer;
            barRenderer.setShadowPaint(WidgetUtils.BG_COLOR_BRIGHT);
            barRenderer.setBarPainter(new StandardBarPainter());
        }

    } else if (plot instanceof XYPlot) {
        // tweaks for line charts
        final XYPlot xyPlot = (XYPlot) plot;

        xyPlot.setDrawingSupplier(new DCDrawingSupplier());

        xyPlot.getDomainAxis().setLabelFont(WidgetUtils.FONT_SMALL);
        xyPlot.getDomainAxis().setTickLabelFont(WidgetUtils.FONT_SMALL);
        xyPlot.getRangeAxis().setLabelFont(WidgetUtils.FONT_SMALL);
        xyPlot.getRangeAxis().setTickLabelFont(WidgetUtils.FONT_SMALL);

        final XYItemRenderer renderer = xyPlot.getRenderer();
        final int seriesCount = xyPlot.getSeriesCount();
        for (int i = 0; i < seriesCount; i++) {
            renderer.setSeriesStroke(i, wideStroke);
        }
    }
}

From source file:org.datacleaner.util.ChartUtils.java

public static void applyStyles(JFreeChart chart) {
    TextTitle title = chart.getTitle();
    if (title != null) {
        title.setFont(WidgetUtils.FONT_HEADER1);
        title.setBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHTEST);
    }// w  w  w . j  a v  a  2 s  . c  om

    for (int i = 0; i < chart.getSubtitleCount(); i++) {
        Title subtitle = chart.getSubtitle(i);
        if (subtitle instanceof TextTitle) {
            ((TextTitle) subtitle).setFont(WidgetUtils.FONT_NORMAL);
        }
    }

    LegendTitle legend = chart.getLegend();
    if (legend != null) {
        legend.setItemFont(WidgetUtils.FONT_SMALL);
    }

    // transparent background
    chart.setBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHTEST);
    chart.setBorderVisible(false);

    final Plot plot = chart.getPlot();
    plot.setInsets(new RectangleInsets(UnitType.ABSOLUTE, 0d, 0d, 0d, 0d));
    plot.setBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHTEST);
    plot.setOutlinePaint(WidgetUtils.BG_COLOR_BRIGHTEST);
    plot.setOutlineVisible(true);

    if (plot instanceof PiePlot) {
        // tweaks for pie charts
        final PiePlot piePlot = (PiePlot) plot;
        piePlot.setBaseSectionOutlinePaint(WidgetUtils.BG_COLOR_DARK);
        piePlot.setBaseSectionOutlineStroke(STROKE_NORMAL);
        piePlot.setLabelFont(WidgetUtils.FONT_SMALL);
        piePlot.setLabelBackgroundPaint(WidgetUtils.BG_COLOR_BRIGHT);
        piePlot.setLabelOutlineStroke(STROKE_NORMAL);
        piePlot.setLabelPaint(WidgetUtils.BG_COLOR_DARK);
        piePlot.setSectionOutlinesVisible(false);
        piePlot.setLabelLinkStyle(PieLabelLinkStyle.QUAD_CURVE);
        piePlot.setDrawingSupplier(new DCDrawingSupplier());

    } else if (plot instanceof CategoryPlot) {
        // tweaks for bar charts
        final CategoryPlot categoryPlot = (CategoryPlot) plot;

        int columnCount = categoryPlot.getDataset().getColumnCount();
        if (columnCount > 1) {
            categoryPlot.setDomainGridlinesVisible(true);
        } else {
            categoryPlot.setDomainGridlinesVisible(false);
        }
        categoryPlot.setDomainGridlinePaint(WidgetUtils.BG_COLOR_DARK);
        categoryPlot.setDomainGridlinePosition(CategoryAnchor.END);

        categoryPlot.getDomainAxis().setLabelFont(WidgetUtils.FONT_SMALL);
        categoryPlot.getDomainAxis().setTickLabelFont(WidgetUtils.FONT_SMALL);
        categoryPlot.getRangeAxis().setLabelFont(WidgetUtils.FONT_SMALL);
        categoryPlot.getRangeAxis().setTickLabelFont(WidgetUtils.FONT_SMALL);
        categoryPlot.setDrawingSupplier(new DCDrawingSupplier());

        final CategoryItemRenderer renderer = categoryPlot.getRenderer();
        renderer.setBaseOutlinePaint(WidgetUtils.BG_COLOR_DARK);
        renderer.setBaseOutlineStroke(STROKE_WIDE);

        if (renderer instanceof BarRenderer) {
            BarRenderer barRenderer = (BarRenderer) renderer;
            barRenderer.setShadowPaint(WidgetUtils.BG_COLOR_BRIGHT);
            barRenderer.setBarPainter(new StandardBarPainter());
        }

    } else if (plot instanceof XYPlot) {
        // tweaks for line charts
        final XYPlot xyPlot = (XYPlot) plot;

        xyPlot.setDrawingSupplier(new DCDrawingSupplier());

        xyPlot.getDomainAxis().setLabelFont(WidgetUtils.FONT_SMALL);
        xyPlot.getDomainAxis().setTickLabelFont(WidgetUtils.FONT_SMALL);
        xyPlot.getRangeAxis().setLabelFont(WidgetUtils.FONT_SMALL);
        xyPlot.getRangeAxis().setTickLabelFont(WidgetUtils.FONT_SMALL);

        final XYItemRenderer renderer = xyPlot.getRenderer();
        final int seriesCount = xyPlot.getSeriesCount();
        for (int i = 0; i < seriesCount; i++) {
            renderer.setSeriesStroke(i, STROKE_WIDE);
        }
    }
}

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createBarChart(null, null, null, categorydataset,
            PlotOrientation.HORIZONTAL, false, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    TextTitle texttitle = new TextTitle(
            "Figure 7 | I. Resources - The site offers users relevant, informative and educational resources");
    texttitle.setHorizontalAlignment(HorizontalAlignment.LEFT);
    texttitle.setBackgroundPaint(Color.red);
    texttitle.setPaint(Color.white);
    jfreechart.setTitle(texttitle);//  ww  w.ja v a2 s.  com
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setOutlinePaint(null);
    categoryplot.setDomainGridlinesVisible(true);
    categoryplot.setDomainGridlinePosition(CategoryAnchor.END);
    categoryplot.setDomainGridlineStroke(new BasicStroke(0.5F));
    categoryplot.setDomainGridlinePaint(Color.black);
    categoryplot.setRangeGridlinesVisible(false);
    categoryplot.clearRangeMarkers();
    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setVisible(false);
    categoryaxis.setCategoryMargin(0.5D);
    categoryplot.getRangeAxis().setVisible(false);
    BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setSeriesPaint(0, new Color(156, 164, 74));
    barrenderer.setDrawBarOutline(false);
    barrenderer.setBaseItemLabelsVisible(true);
    barrenderer.setBaseItemLabelFont(new Font("SansSerif", 1, 10));
    ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE3,
            TextAnchor.CENTER_RIGHT);
    barrenderer.setBasePositiveItemLabelPosition(itemlabelposition);
    CategoryTextAnnotation categorytextannotation = new CategoryTextAnnotation("1. White papers are available.",
            "Category 1", 0.0D);
    categorytextannotation.setFont(new Font("SansSerif", 1, 12));
    categorytextannotation.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categorytextannotation.setCategoryAnchor(CategoryAnchor.START);
    categoryplot.addAnnotation(categorytextannotation);
    CategoryTextAnnotation categorytextannotation1 = new CategoryTextAnnotation(
            "2. White papers enhance users understanding of the firm and its expertise.", "Category 2", 0.0D);
    categorytextannotation1.setFont(new Font("SansSerif", 0, 12));
    categorytextannotation1.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categorytextannotation1.setCategoryAnchor(CategoryAnchor.START);
    categoryplot.addAnnotation(categorytextannotation1);
    CategoryTextAnnotation categorytextannotation2 = new CategoryTextAnnotation(
            "3. White papers are relevant to the firm's prospects and clients.", "Category 3", 0.0D);
    categorytextannotation2.setFont(new Font("SansSerif", 0, 12));
    categorytextannotation2.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categorytextannotation2.setCategoryAnchor(CategoryAnchor.START);
    categoryplot.addAnnotation(categorytextannotation2);
    CategoryTextAnnotation categorytextannotation3 = new CategoryTextAnnotation(
            "4. White papers are relevant to the firm's positioning.", "Category 4", 0.0D);
    categorytextannotation3.setFont(new Font("SansSerif", 0, 12));
    categorytextannotation3.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categorytextannotation3.setCategoryAnchor(CategoryAnchor.START);
    categoryplot.addAnnotation(categorytextannotation3);
    CategoryTextAnnotation categorytextannotation4 = new CategoryTextAnnotation(
            "5. Case studies are available.", "Category 5", 0.0D);
    categorytextannotation4.setFont(new Font("SansSerif", 1, 12));
    categorytextannotation4.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categorytextannotation4.setCategoryAnchor(CategoryAnchor.START);
    categoryplot.addAnnotation(categorytextannotation4);
    CategoryTextAnnotation categorytextannotation5 = new CategoryTextAnnotation(
            "6. Case studies enhance users understanding of the firm and its expertise.", "Category 6", 0.0D);
    categorytextannotation5.setFont(new Font("SansSerif", 0, 12));
    categorytextannotation5.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categorytextannotation5.setCategoryAnchor(CategoryAnchor.START);
    categoryplot.addAnnotation(categorytextannotation5);
    CategoryTextAnnotation categorytextannotation6 = new CategoryTextAnnotation(
            "7. Case studies are relevant to the firm's prospects and clients.", "Category 7", 0.0D);
    categorytextannotation6.setFont(new Font("SansSerif", 0, 12));
    categorytextannotation6.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categorytextannotation6.setCategoryAnchor(CategoryAnchor.START);
    categoryplot.addAnnotation(categorytextannotation6);
    CategoryTextAnnotation categorytextannotation7 = new CategoryTextAnnotation(
            "8. White papers are relevant to the firm's positioning.", "Category 8", 0.0D);
    categorytextannotation7.setFont(new Font("SansSerif", 0, 12));
    categorytextannotation7.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categorytextannotation7.setCategoryAnchor(CategoryAnchor.START);
    categoryplot.addAnnotation(categorytextannotation7);
    CategoryTextAnnotation categorytextannotation8 = new CategoryTextAnnotation(
            "9. Case studies are available.", "Category 9", 0.0D);
    categorytextannotation8.setFont(new Font("SansSerif", 1, 12));
    categorytextannotation8.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categorytextannotation8.setCategoryAnchor(CategoryAnchor.START);
    categoryplot.addAnnotation(categorytextannotation8);
    CategoryTextAnnotation categorytextannotation9 = new CategoryTextAnnotation(
            "10. Case studies enhance users understanding of the firm and its expertise.", "Category 10", 0.0D);
    categorytextannotation9.setFont(new Font("SansSerif", 0, 12));
    categorytextannotation9.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categorytextannotation9.setCategoryAnchor(CategoryAnchor.START);
    categoryplot.addAnnotation(categorytextannotation9);
    CategoryTextAnnotation categorytextannotation10 = new CategoryTextAnnotation(
            "11. Case studies are relevant to the firm's prospects and clients.", "Category 11", 0.0D);
    categorytextannotation10.setFont(new Font("SansSerif", 0, 12));
    categorytextannotation10.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categorytextannotation10.setCategoryAnchor(CategoryAnchor.START);
    categoryplot.addAnnotation(categorytextannotation10);
    CategoryTextAnnotation categorytextannotation11 = new CategoryTextAnnotation(
            "12. White papers are relevant to the firm's positioning.", "Category 12", 0.0D);
    categorytextannotation11.setFont(new Font("SansSerif", 0, 12));
    categorytextannotation11.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categorytextannotation11.setCategoryAnchor(CategoryAnchor.START);
    categoryplot.addAnnotation(categorytextannotation11);
    CategoryTextAnnotation categorytextannotation12 = new CategoryTextAnnotation(
            "13. Users can easily access resources based on viewer interest.", "Category 13", 0.0D);
    categorytextannotation12.setFont(new Font("SansSerif", 1, 12));
    categorytextannotation12.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categorytextannotation12.setCategoryAnchor(CategoryAnchor.START);
    categoryplot.addAnnotation(categorytextannotation12);
    CategoryTextAnnotation categorytextannotation13 = new CategoryTextAnnotation(
            "14. Access to additional hyperlinks enhances users's ability to find relevant information.",
            "Category 14", 0.0D);
    categorytextannotation13.setFont(new Font("SansSerif", 1, 12));
    categorytextannotation13.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categorytextannotation13.setCategoryAnchor(CategoryAnchor.START);
    categoryplot.addAnnotation(categorytextannotation13);
    CategoryTextAnnotation categorytextannotation14 = new CategoryTextAnnotation("15. OVERALL EFFECTIVENESS.",
            "Overall", 0.0D);
    categorytextannotation14.setFont(new Font("SansSerif", 1, 12));
    categorytextannotation14.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    categorytextannotation14.setCategoryAnchor(CategoryAnchor.START);
    categoryplot.addAnnotation(categorytextannotation14);
    return jfreechart;
}

From source file:com.greenpepper.confluence.macros.historic.AbstractChartBuilder.java

protected void customizeTitle(TextTitle title, Font font) {
    title.setFont(font);//from   ww w.  j ava 2 s. co m
    title.setTextAlignment(HorizontalAlignment.LEFT);
    title.setPaint(Color.BLACK);
    title.setBackgroundPaint(TRANSPARENT_COLOR);
}

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

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

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

    TextTitle title = chart.getTitle();
    title.setBorder(0, 0, 1, 0);
    title.setBackgroundPaint(new GradientPaint(0f, 0f, Color.red, 350f, 0f, Color.white, true));
    title.setExpandToFitSpace(true);

    chart.setBackgroundPaint(new GradientPaint(0f, 0f, Color.yellow, 350f, 0f, Color.white, true));

    // get a reference to the plot for further customisation...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setNoDataMessage("NO DATA!");
    plot.setBackgroundPaint(null);
    plot.setInsets(new RectangleInsets(10, 5, 5, 5));
    plot.setOutlinePaint(Color.black);
    plot.setRangeGridlinePaint(Color.gray);
    plot.setRangeGridlineStroke(new BasicStroke(1.0f));
    Paint[] colors = createPaint();
    CustomBarRenderer renderer = new CustomBarRenderer(colors);
    renderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_HORIZONTAL));
    plot.setRenderer(renderer);

    renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());

    // change the margin at the top of the range axis...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    //   rangeAxis.setRange(0.0, 800.0);
    rangeAxis.setTickMarkPaint(Color.black);

    setCategorySummary(dataset);
    return chart;

}

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

/**
 * Creates a chart.//from   w  ww. j av  a  2s  . 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.VERTICAL, // orientation
            false, // include legend
            true, false);

    chart.setBackgroundPaint(Color.white);
    chart.getPlot().setOutlinePaint(null);
    final TextTitle title = new TextTitle("Figure 8.5 - Case studies are available");
    title.setHorizontalAlignment(HorizontalAlignment.LEFT);
    title.setBackgroundPaint(Color.red);
    title.setPaint(Color.white);

    chart.setTitle(title);
    final CategoryPlot plot = chart.getCategoryPlot();

    final ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setRange(0.0, 5.0);
    rangeAxis.setVisible(false);

    final ExtendedCategoryAxis domainAxis = new ExtendedCategoryAxis(null);
    domainAxis.setTickLabelFont(new Font("SansSerif", Font.BOLD, 12));
    domainAxis.setCategoryMargin(0.30);
    domainAxis.addSubLabel("Sm.", "(10)");
    domainAxis.addSubLabel("Med.", "(10)");
    domainAxis.addSubLabel("Lg.", "(10)");
    domainAxis.addSubLabel("All", "(10)");
    plot.setDomainAxis(domainAxis);

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

    renderer.setItemLabelsVisible(true);
    renderer.setItemLabelFont(new Font("SansSerif", Font.PLAIN, 18));
    final ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.INSIDE12, TextAnchor.TOP_CENTER);
    renderer.setPositiveItemLabelPosition(position);
    renderer.setPositiveItemLabelPositionFallback(new ItemLabelPosition());

    return chart;

}

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

/**
 * Creates a chart./*from   ww w .  j  a v a2s.com*/
 * 
 * @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);
    chart.getPlot().setOutlinePaint(null);
    final TextTitle title = new TextTitle("Figure 6 | Overall SEO Rating");
    title.setHorizontalAlignment(HorizontalAlignment.LEFT);
    title.setBackgroundPaint(Color.red);
    title.setPaint(Color.white);

    chart.setTitle(title);
    final CategoryPlot plot = chart.getCategoryPlot();

    final ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setRange(0.0, 4.0);
    rangeAxis.setVisible(false);

    final ExtendedCategoryAxis domainAxis = new ExtendedCategoryAxis(null);
    domainAxis.setTickLabelFont(new Font("SansSerif", Font.BOLD, 12));
    domainAxis.setCategoryMargin(0.30);
    domainAxis.addSubLabel("Sm.", "(10)");
    domainAxis.addSubLabel("Med.", "(10)");
    domainAxis.addSubLabel("Lg.", "(10)");
    domainAxis.addSubLabel("All", "(10)");
    final CategoryLabelPositions p = domainAxis.getCategoryLabelPositions();
    final CategoryLabelPosition left = new CategoryLabelPosition(RectangleAnchor.LEFT,
            TextBlockAnchor.CENTER_LEFT);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.replaceLeftPosition(p, left));
    plot.setDomainAxis(domainAxis);

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

    //        final StandardCategoryLabelGenerator generator = new StandardCategoryLabelGenerator(
    //          "{2}", new DecimalFormat("0.00")
    //    );
    //  renderer.setLabelGenerator(generator);
    renderer.setItemLabelsVisible(true);
    renderer.setItemLabelFont(new Font("SansSerif", Font.PLAIN, 18));
    final ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.INSIDE3, TextAnchor.CENTER_RIGHT);
    renderer.setPositiveItemLabelPosition(position);
    renderer.setPositiveItemLabelPositionFallback(new ItemLabelPosition());

    return chart;

}

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

/**
 * Creates a chart./*from  w  ww .ja  v  a 2  s  .  co m*/
 * 
 * @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.xpn.xwiki.plugin.charts.ChartCustomizer.java

public static void customizeTitle(TextTitle title, ChartParams params, String prefix) {
    if (params.get(prefix + ChartParams.TITLE_FONT_SUFFIX) != null) {
        title.setFont(params.getFont(prefix + ChartParams.TITLE_FONT_SUFFIX));
    } else {//from   w w  w  .j a  v a  2s . c o  m
        title.setFont(JFreeChart.DEFAULT_TITLE_FONT);
    }

    if (params.get(prefix + ChartParams.TITLE_POSITION_SUFFIX) != null) {
        title.setPosition(params.getRectangleEdge(prefix + ChartParams.TITLE_POSITION_SUFFIX));
    }

    if (params.get(prefix + ChartParams.TITLE_HORIZONTAL_ALIGNMENT_SUFFIX) != null) {
        title.setHorizontalAlignment(
                params.getHorizontalAlignment(prefix + ChartParams.TITLE_HORIZONTAL_ALIGNMENT_SUFFIX));
    }

    if (params.get(prefix + ChartParams.TITLE_VERTICAL_ALIGNMENT_SUFFIX) != null) {
        title.setVerticalAlignment(
                params.getVerticalAlignment(prefix + ChartParams.TITLE_VERTICAL_ALIGNMENT_SUFFIX));
    }

    if (params.get(prefix + ChartParams.TITLE_COLOR_SUFFIX) != null) {
        title.setPaint(params.getColor(prefix + ChartParams.TITLE_COLOR_SUFFIX));
    }

    if (params.get(prefix + ChartParams.TITLE_BACKGROUND_COLOR_SUFFIX) != null) {
        title.setBackgroundPaint(params.getColor(prefix + ChartParams.TITLE_BACKGROUND_COLOR_SUFFIX));
    }

    if (params.get(prefix + ChartParams.TITLE_PADDING_SUFFIX) != null) {
        title.setPadding(params.getRectangleInsets(prefix + ChartParams.TITLE_PADDING_SUFFIX));
    }

    if (params.get(prefix + ChartParams.TITLE_URL_SUFFIX) != null) {
        title.setURLText(params.getString(prefix + ChartParams.TITLE_URL_SUFFIX));
    }
}