Example usage for java.awt GradientPaint GradientPaint

List of usage examples for java.awt GradientPaint GradientPaint

Introduction

In this page you can find the example usage for java.awt GradientPaint GradientPaint.

Prototype

public GradientPaint(float x1, float y1, Color color1, float x2, float y2, Color color2) 

Source Link

Document

Constructs a simple acyclic GradientPaint object.

Usage

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

/**
 * Create and display an overlaid chart.
 * /*  w ww  .ja  va  2 s  .c om*/
 * @param frameTitle
 *           the frame title.
 * @param data1
 *           dataset1.
 * @param data2
 *           dataset2.
 */
private static void displayYSymbolicOverlaid(final String frameTitle, final XYDataset data1,
        final XYDataset data2) {

    final String title = "Animals Overlaid";
    final String xAxisLabel = "Miles";
    final String yAxisLabel = "Animal";

    // combine the y symbolic values of the two data sets...
    final String[] combinedYSymbolicValues = SampleYSymbolicDataset.combineYSymbolicDataset((YisSymbolic) data1,
            (YisSymbolic) data2);

    // make master dataset...
    final CombinedDataset data = new CombinedDataset();
    data.add(data1);
    data.add(data2);

    // decompose data...
    final XYDataset series0 = new SubSeriesDataset(data, 0);
    final XYDataset series1 = new SubSeriesDataset(data, 1);
    final XYDataset series2 = new SubSeriesDataset(data, 2);
    final XYDataset series3 = new SubSeriesDataset(data, 3);
    final XYDataset series4 = new SubSeriesDataset(data, 4);
    final XYDataset series5 = new SubSeriesDataset(data, 5);
    final XYDataset series6 = new SubSeriesDataset(data, 6);
    final XYDataset series7 = new SubSeriesDataset(data, 7);

    // create main plot...
    final ValueAxis valueAxis = new NumberAxis(xAxisLabel);
    final SymbolicAxis symbolicAxis = new SymbolicAxis(yAxisLabel, combinedYSymbolicValues);
    final XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    final XYPlot plot = new XYPlot(series0, valueAxis, symbolicAxis, renderer);

    plot.setDataset(1, series1);
    final XYItemRenderer renderer1 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    plot.setRenderer(1, renderer1);

    plot.setDataset(2, series2);
    final XYItemRenderer renderer2 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    plot.setRenderer(2, renderer2);

    plot.setDataset(3, series3);
    final XYItemRenderer renderer3 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    plot.setRenderer(3, renderer3);

    plot.setDataset(4, series4);
    final XYItemRenderer renderer4 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    plot.setRenderer(4, renderer4);

    plot.setDataset(5, series5);
    final XYItemRenderer renderer5 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    plot.setRenderer(5, renderer5);

    plot.setDataset(6, series6);
    final XYItemRenderer renderer6 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    plot.setRenderer(6, renderer6);

    plot.setDataset(7, series7);
    final XYItemRenderer renderer7 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    plot.setRenderer(7, renderer7);

    // make the chart...
    final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue));

    // and present it in a frame...
    final JFrame frame = new ChartFrame(frameTitle, chart);
    frame.pack();
    RefineryUtilities.positionFrameRandomly(frame);
    frame.show();

}

From source file:com.opensourcestrategies.crmsfa.reports.JFreeCrmsfaCharts.java

/**
 * Opportunities by stage.  Description at
 * http://www.opentaps.org/docs/index.php/CRMSFA_Dashboard
 * Note that this counts all the opportunities in the system for now.
 *//*  www  . j a  v a 2 s  . c  om*/
public static String createOpportunitiesbyStageChart(Delegator delegator, Locale locale)
        throws GenericEntityException, IOException {
    Map uiLabelMap = UtilMessage.getUiLabels(locale);

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    String currency = UtilConfig.getPropertyValue("crmsfa", "defaultCurrencyUomId");

    // get all sales opportunity stages that are not closed, or lost
    List<GenericValue> salesOpportunityStages = ReportHelper
            .findSalesOpportunityStagesForDashboardReporting(delegator);

    // report number of leads for each status
    for (GenericValue stage : salesOpportunityStages) {
        String opportunityStageId = stage.getString("opportunityStageId");
        EntityCondition conditions = EntityCondition.makeCondition(EntityOperator.AND,
                EntityCondition.makeCondition("opportunityStageId", EntityOperator.EQUALS, opportunityStageId),
                EntityCondition.makeCondition("currencyUomId", EntityOperator.EQUALS, currency));
        List<GenericValue> salesOpportunityEstimatedAmountTotals = delegator
                .findByConditionCache("SalesOpportunityEstimatedAmountTotalByStage", conditions, null, null);

        if (salesOpportunityEstimatedAmountTotals != null && !salesOpportunityEstimatedAmountTotals.isEmpty()) {
            GenericValue salesOpportunityEstimatedAmountTotal = salesOpportunityEstimatedAmountTotals.get(0);
            dataset.addValue(salesOpportunityEstimatedAmountTotal.getDouble("estimatedAmountTotal"), "",
                    (String) stage.get("description", locale));
        } else {
            dataset.addValue(0, "", (String) stage.get("description", locale));
        }
    }

    // set up the chart
    JFreeChart chart = ChartFactory.createBarChart(
            (String) UtilMessage.expandLabel("CrmOpportunitiesbyStage", locale,
                    UtilMisc.toMap("currency", currency)),
            null, null, dataset, PlotOrientation.HORIZONTAL, false, true, false);
    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setPadding(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    // get the bar renderer to put effects on the bars
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false); // disable bar outlines

    // set up gradient paint on bar
    final GradientPaint gp = new GradientPaint(0.0f, 0.0f, new Color(206, 246, 245), 0.0f, 0.0f,
            new Color(51, 204, 204));
    renderer.setSeriesPaint(0, gp);

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

    // save as a png and return the file name
    return ServletUtilities.saveChartAsPNG(chart, 360, 200, null);
}

From source file:com.manydesigns.portofino.chart.Chart1DGenerator.java

public JFreeChart generate(ChartDefinition chartDefinition, Persistence persistence, Locale locale) {
    DefaultPieDataset dataset = new DefaultPieDataset();
    java.util.List<Object[]> result;
    String query = chartDefinition.getQuery();
    logger.info(query);/*from   www  .  jav a2s . co  m*/
    Session session = persistence.getSession(chartDefinition.getDatabase());
    result = QueryUtils.runSql(session, query);
    for (Object[] current : result) {
        ComparableWrapper key = new ComparableWrapper((Comparable) current[0]);
        dataset.setValue(key, (Number) current[1]);
        if (current.length > 2) {
            key.setLabel(current[2].toString());
        }
    }

    JFreeChart chart = createChart(chartDefinition, dataset);

    chart.setAntiAlias(isAntiAlias());

    // impostiamo il bordo invisibile
    // eventualmente e' il css a fornirne uno
    // eventualmente e' il css a fornirne uno
    chart.setBorderVisible(isBorderVisible());

    // impostiamo il titolo
    TextTitle title = chart.getTitle();
    title.setFont(titleFont);
    title.setMargin(10.0, 0.0, 0.0, 0.0);

    // ottieni il Plot
    PiePlot plot = (PiePlot) chart.getPlot();

    String urlExpression = chartDefinition.getUrlExpression();
    if (!StringUtils.isBlank(urlExpression)) {
        PieURLGenerator urlGenerator = new ChartPieUrlGenerator(urlExpression);
        plot.setURLGenerator(urlGenerator);
    } else {
        plot.setURLGenerator(null);
    }

    // il plot ha sfondo e bordo trasparente
    // (quindi si vede il colore del chart)
    plot.setBackgroundPaint(transparentColor);
    plot.setOutlinePaint(transparentColor);

    // Modifico il toolTip
    // hongliangpan add
    // :?{0}  {1}  {2} ? ,???
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})",
            NumberFormat.getNumberInstance(), new DecimalFormat("0.00%")));
    // {0}={1}({2})
    plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}"));
    // ?(0.0-1.0)
    // plot.setForegroundAlpha(1.0f);
    // imposta la distanza delle etichette dal plot
    plot.setLabelGap(0.03);
    // plot.setLabelGenerator(new MyPieSectionLabelGenerator());

    // imposta il messaggio se non ci sono dati
    plot.setNoDataMessage(ElementsThreadLocals.getText("no.data.available"));

    plot.setCircular(true);

    plot.setBaseSectionOutlinePaint(Color.BLACK);

    DrawingSupplier supplier = new DesaturatedDrawingSupplier(plot.getDrawingSupplier());
    plot.setDrawingSupplier(supplier);
    // ?
    plot.setForegroundAlpha(1.0f);
    // impostiamo il titolo della legenda
    String legendString = chartDefinition.getLegend();
    Title subtitle = new TextTitle(legendString, legendFont, Color.BLACK, RectangleEdge.BOTTOM,
            HorizontalAlignment.CENTER, VerticalAlignment.CENTER, new RectangleInsets(0, 0, 0, 0));
    subtitle.setMargin(0, 0, 5, 0);
    chart.addSubtitle(subtitle);

    // impostiamo la legenda
    LegendTitle legend = chart.getLegend();
    legend.setBorder(0, 0, 0, 0);
    legend.setItemFont(legendItemFont);
    int legendMargin = 10;
    legend.setMargin(0.0, legendMargin, legendMargin, legendMargin);
    legend.setBackgroundPaint(transparentColor);

    // impostiamo un gradiente orizzontale
    Paint chartBgPaint = new GradientPaint(0, 0, new Color(255, 253, 240), 0, getHeight(), Color.WHITE);
    chart.setBackgroundPaint(chartBgPaint);
    return chart;
}

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

/**
 * Create a chart representing an arbitrary collection of name/value pairs. 
 * The data is passed in as a hashtable where the key is the name and the  
 * value is the number items. /*from w w w.j  ava  2  s  .c  om*/
 */
public static final JFreeChart getBarChart(Hashtable<String, Integer> data, String title, String nameLabel,
        String valueLabel) {
    JFreeChart chart = null;

    // Sort the data by name
    Vector<String> names = new Vector<String>();
    Enumeration nameList = data.keys();
    while (nameList.hasMoreElements()) {
        names.add((String) nameList.nextElement());
    }
    Collections.sort(names);

    // Populate the dataset with data
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    Iterator keyIter = names.iterator();
    while (keyIter.hasNext()) {
        String name = (String) keyIter.next();
        Integer value = data.get(name);
        dataset.addValue(value, valueLabel, name);
    }

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

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

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

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

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

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

    return chart;
}

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

/**
 * Creates a sample chart./*from w w w .  java  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?
    );

    // 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...
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    IntervalMarker target = new IntervalMarker(4.5, 7.5);
    target.setLabel("Target Range");
    target.setLabelFont(new Font("SansSerif", Font.ITALIC, 11));
    target.setLabelAnchor(RectangleAnchor.LEFT);
    target.setLabelTextAnchor(TextAnchor.CENTER_LEFT);
    target.setPaint(new Color(222, 222, 255, 128));
    plot.addRangeMarker(target, Layer.BACKGROUND);

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

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setItemMargin(0.10);

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray);
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray);
    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);
    renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());

    renderer.setBaseItemLabelGenerator(new CustomCategoryItemLabelGenerator());
    renderer.setBaseItemLabelsVisible(true);
    ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.INSIDE12, TextAnchor.CENTER_RIGHT,
            TextAnchor.CENTER_RIGHT, -Math.PI / 2.0);
    renderer.setBasePositiveItemLabelPosition(p);

    ItemLabelPosition p2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER_LEFT,
            TextAnchor.CENTER_LEFT, -Math.PI / 2.0);
    renderer.setPositiveItemLabelPositionFallback(p2);
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    // OPTIONAL CUSTOMISATION COMPLETED.
    setCategorySummary(dataset);
    return chart;

}

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

/**
 * Displays an XYPlot with symbolic axes.
 * /*  w  w  w.  j  a v  a  2 s .  c o m*/
 * @param frameTitle
 *           the frame title.
 * @param data
 *           the dataset.
 * @param chartTitle
 *           the chart title.
 * @param xAxisLabel
 *           the x axis label.
 * @param yAxisLabel
 *           the y axis label.
 */
private static void displayXYSymbolic(final String frameTitle, final XYDataset data, final String chartTitle,
        final String xAxisLabel, final String yAxisLabel) {

    final JFreeChart chart = createXYSymbolicPlot(chartTitle, xAxisLabel, yAxisLabel, data, true);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.green));
    final JFrame frame = new ChartFrame(frameTitle, chart);
    frame.pack();
    RefineryUtilities.positionFrameRandomly(frame);
    frame.show();

}

From source file:org.psystems.dicom.browser.server.stat.StatClientRequestsChartServlet.java

public JFreeChart getChart(CategoryDataset dataset) {
    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("? ?", // chart title
            "", // domain axis label
            "? (.)", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );//from  w w  w  .j a  v  a 2  s .com

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

    // final IntervalMarker target = new IntervalMarker(2000000, 3000000);
    // target.setLabel(" ");
    // target.setLabelFont(new Font("SansSerif", Font.ITALIC, 11));
    // target.setLabelAnchor(RectangleAnchor.LEFT);
    // target.setLabelTextAnchor(TextAnchor.CENTER_LEFT);
    // target.setPaint(new Color(222, 222, 255, 128));
    // plot.addRangeMarker(target, Layer.BACKGROUND);

    // 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);
    renderer.setItemMargin(0.10);

    // 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 / 4.0)
    // CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)
    );
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;
}

From source file:com.argeloji.server.BarChartDemo4.java

/**
 * Creates a sample chart./*  w  ww . j av  a2s . c  om*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Cevap Dalm", // chart title
            "Seenekler", // domain axis label
            "renci Says", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, 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(0xFFFFFF));

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

    // 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);
    //renderer.setMaxBarWidth(0.10);

    // set up gradient paints for series...
    final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.GREEN, 0.0f, 0.0f, Color.GREEN);
    final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.RED, 0.0f, 0.0f, Color.RED);
    final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.RED, 0.0f, 0.0f, Color.RED);
    final GradientPaint gp3 = new GradientPaint(0.0f, 0.0f, Color.RED, 0.0f, 0.0f, Color.RED);
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);
    renderer.setSeriesPaint(3, gp3);

    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:net.sourceforge.subsonic.controller.FolderChartController.java

private JFreeChart createChart(CategoryDataset dataset, HttpServletRequest request) {
    JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.HORIZONTAL, false,
            false, false);/*ww  w .  jav  a  2s .  co m*/
    CategoryPlot plot = chart.getCategoryPlot();
    Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_MIN_HEIGHT, Color.white);
    plot.setBackgroundPaint(background);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.gray);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    LogarithmicAxis rangeAxis = new LogarithmicAxis(null);
    rangeAxis.setStrictValuesFlag(false);
    rangeAxis.setAllowNegativesFlag(true);
    //        rangeAxis.setTickUnit(new NumberTickUnit(.1, new DecimalFormat("##0%")));
    plot.setRangeAxis(rangeAxis);

    // Disable bar outlines.
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // Set up gradient paint for series.
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.gray, 0.0f, 0.0f, new Color(0, 0, 64));
    renderer.setSeriesPaint(0, gp0);

    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setBaseItemLabelFont(new Font("SansSerif", Font.BOLD, 11));
    renderer.setItemLabelAnchorOffset(-45.0);

    renderer.setSeriesItemLabelPaint(0, Color.white);
    renderer.setBaseItemLabelPaint(Color.white);

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

    // Set theme-specific colors.
    Color bgColor = getBackground(request);
    Color fgColor = getForeground(request);

    chart.setBackgroundPaint(bgColor);

    domainAxis.setTickLabelPaint(fgColor);
    domainAxis.setTickMarkPaint(fgColor);
    domainAxis.setAxisLinePaint(fgColor);

    rangeAxis.setTickLabelPaint(fgColor);
    rangeAxis.setTickMarkPaint(fgColor);
    rangeAxis.setAxisLinePaint(fgColor);

    return chart;
}

From source file:j2se.jfreechart.barchart.BarChartDemo7.java

/**
 * Creates a sample chart./*from  ww  w .ja 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 7", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // 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);

    final IntervalMarker target = new IntervalMarker(4.5, 7.5);
    target.setLabel("Target Range");
    target.setLabelFont(new Font("SansSerif", Font.ITALIC, 11));
    target.setLabelAnchor(RectangleAnchor.LEFT);
    target.setLabelTextAnchor(TextAnchor.CENTER_LEFT);
    target.setPaint(new Color(222, 222, 255, 128));
    plot.addRangeMarker(target, Layer.BACKGROUND);

    // 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);
    renderer.setItemMargin(0.10);

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

    //      renderer.setLabelGenerator(new BarChartDemo7.LabelGenerator());
    renderer.setItemLabelsVisible(true);
    final ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.INSIDE12, TextAnchor.CENTER_RIGHT,
            TextAnchor.CENTER_RIGHT, -Math.PI / 2.0);
    renderer.setPositiveItemLabelPosition(p);

    final ItemLabelPosition p2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER_LEFT,
            TextAnchor.CENTER_LEFT, -Math.PI / 2.0);
    renderer.setPositiveItemLabelPositionFallback(p2);
    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}