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.ContourPlotDemo2.java

/**
 * Creates a ContourPlot chart./*  w  w w.  j  a  v  a 2 s. co m*/
 *
 * @return the ContourPlot chart.
 */
private JFreeChart createContourPlot() {

    final String title = "Contour Plot";
    final String xAxisLabel = "X Values";
    final String yAxisLabel = "Y Values";
    final String zAxisLabel = "Color Values";

    if (xIsDate) {
        this.xAxis = new DateAxis(xAxisLabel);
        xIsLog = false; // force axis to be linear when displaying dates
    } else {
        if (xIsLog) {
            this.xAxis = new LogarithmicAxis(xAxisLabel);
        } else {
            this.xAxis = new NumberAxis(xAxisLabel);
        }
    }

    if (yIsLog) {
        this.yAxis = new LogarithmicAxis(yAxisLabel);
    } else {
        this.yAxis = new NumberAxis(yAxisLabel);
    }

    if (zIsLog) {
        this.zColorBar = new ColorBar(zAxisLabel);
    } else {
        this.zColorBar = new ColorBar(zAxisLabel);
    }

    if (this.xAxis instanceof NumberAxis) {
        ((NumberAxis) this.xAxis).setAutoRangeIncludesZero(false);
        ((NumberAxis) this.xAxis).setInverted(xIsInverted);
    }

    this.yAxis.setAutoRangeIncludesZero(false);

    this.yAxis.setInverted(yIsInverted);

    if (!xIsDate) {
        ((NumberAxis) this.xAxis).setLowerMargin(0.0);
        ((NumberAxis) this.xAxis).setUpperMargin(0.0);
    }

    this.yAxis.setLowerMargin(0.0);
    this.yAxis.setUpperMargin(0.0);

    if (!xIsDate) {
        this.xAxis.setRange(10.5, 15.0);
    }
    this.yAxis.setRange(3.5, 7.0);

    this.zColorBar.getAxis().setInverted(zIsInverted);
    this.zColorBar.getAxis().setTickMarksVisible(true);

    final ContourDataset data = createDataset();

    final ContourPlot plot = new ContourPlot(data, this.xAxis, this.yAxis, this.zColorBar);

    if (xIsDate) {
        ratio = Math.abs(ratio); // don't use plot units for ratios when x axis is date
    }

    if (asPoints) {
        plot.setRenderAsPoints(true);
    }
    plot.setDataAreaRatio(ratio);

    if (annotate) {
        if (asPoints) {
            final Number[] xValues = data.getXValues();
            final Number[] yValues = data.getYValues();
            //Number[] zValues = data.getZValues();

            final Font font = new Font("SansSerif", Font.PLAIN, 20);

            for (int i = 0; i < xValues.length; i++) {
                final XYTextAnnotation xyAnn = new XYTextAnnotation(Integer.toString(i),
                        xValues[i].doubleValue(), yValues[i].doubleValue());
                xyAnn.setFont(font);
                plot.addAnnotation(xyAnn);
            }
        } else {
            final Font font = new Font("SansSerif", Font.PLAIN, 20);

            for (int i = 0; i < this.tmpDoubleX.length; i++) {
                final XYTextAnnotation xyAnn = new XYTextAnnotation(Integer.toString(i), this.tmpDoubleX[i],
                        this.tmpDoubleY[i]);
                xyAnn.setFont(font);
                plot.addAnnotation(xyAnn);
            }
        }

    }

    if (fillOutline || drawOutline) {
        initShoreline();
        plot.setClipPath(new ClipPath(this.xOutline, this.yOutline, true, fillOutline, drawOutline));
    }

    final JFreeChart chart = new JFreeChart(title, null, plot, false);

    // then customise it a little...
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.green));

    return chart;

}

From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo.java

private static JFreeChart createStackedBarChart(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createStackedBarChart("StackedBar Chart Demo 1", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/*from   www.  j ava2 s  .  com*/

    chart.setBackgroundPaint(Color.white);

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

    return chart;

}

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

/**
 * Displays an overlaid XYPlot with X and Y symbolic data.
 * /*from w ww.jav  a2s .  c  om*/
 * @param frameTitle
 *           the frame title.
 * @param data1
 *           the dataset 1.
 * @param data2
 *           the dataset 2.
 */
private static void displayXYSymbolicOverlaid(final String frameTitle, final XYDataset data1,
        final XYDataset data2) {

    final String title = "Pollutant Overlaid";
    final String xAxisLabel = "Contamination and Type";
    final String yAxisLabel = "Pollutant";

    // combine the x symbolic values of the two data sets
    final String[] combinedXSymbolicValues = SampleXYSymbolicDataset
            .combineXSymbolicDataset((XisSymbolic) data1, (XisSymbolic) data2);

    // combine the y symbolic values of the two data sets
    final String[] combinedYSymbolicValues = SampleXYSymbolicDataset
            .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);

    // create overlaid plot...
    final SymbolicAxis hsymbolicAxis = new SymbolicAxis(xAxisLabel, combinedXSymbolicValues);
    final SymbolicAxis vsymbolicAxis = new SymbolicAxis(yAxisLabel, combinedYSymbolicValues);

    final XYItemRenderer renderer1 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    final XYPlot plot = new XYPlot(series0, hsymbolicAxis, vsymbolicAxis, renderer1);

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

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

/**
 * Open Cases snapshot.  Description at http://www.opentaps.org/docs/index.php/CRMSFA_Dashboard
 * Note that this counts all the cases in the system for now.
 *///from  w  ww .  ja v a 2  s.  c  o m
public static String createOpenCasesChart(Delegator delegator, Locale locale)
        throws GenericEntityException, IOException {
    Map uiLabelMap = UtilMessage.getUiLabels(locale);

    // create the dataset
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    // get all case statuses that are not "closed" (this is dynamic because statuses may be added at run time)
    List<GenericValue> statuses = ReportHelper.findCasesStagesForDashboardReporting(delegator);

    // Report number of cases for each status
    for (GenericValue status : statuses) {
        String statusId = status.getString("statusId");
        long count = delegator.findCountByCondition("CustRequest",
                EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, statusId), null);
        dataset.addValue(count, "", (String) status.get("description", locale));
    }

    // set up the chart
    JFreeChart chart = ChartFactory.createBarChart((String) uiLabelMap.get("CrmOpenCases"), // chart title
            null, // domain axis label
            null, // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );
    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(246, 227, 206), 0.0f, 0.0f,
            new Color(204, 153, 102));
    renderer.setSeriesPaint(0, gp);

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

    // tilt the category labels so they fit
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

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

From source file:org.testeditor.dashboard.TableDurationTrend.java

/**
 * designs and creates graph from data sets.
 * /*from  ww  w .  ja  v a 2s  .c  o m*/
 * @param objektList
 *            list of all suite GoogleSucheSuite runs <AllRunsResult>
 * @param parent
 *            composite parent
 * @param modelService
 *            to find part label
 * @param window
 *            trimmed window
 * @param app
 *            org.eclipse.e4.ide.application
 */
@SuppressWarnings({ "serial" })
@Inject
@Optional
public void createControls(@UIEventTopic("Testobjektlist") List<AllRunsResult> objektList, Composite parent,
        EModelService modelService, MWindow window, MApplication app) {
    MPart mPart = (MPart) modelService.find("org.testeditor.ui.part.2", app);
    String[] arr = objektList.get(0).getFilePath().getName().split("\\.");
    String filenameSplitted = arr[arr.length - 1];
    mPart.setLabel(translationService.translate("%dashboard.table.label.duration", CONTRIBUTOR_URI) + " "
            + filenameSplitted);
    mPart.setTooltip(translationService.translate("%dashboard.table.label.duration", CONTRIBUTOR_URI) + " "
            + objektList.get(0).getFilePath().getName());
    parent.setLayout(new FillLayout());

    // create the chart...
    chart = ChartFactory.createBarChart3D(null, // chart
            // title
            translationService.translate("%dashboard.table.label.duration.axis.dates", CONTRIBUTOR_URI), // domain
            // X axis
            // label
            translationService.translate("%dashboard.table.label.duration.axis.duration", CONTRIBUTOR_URI)
                    + " h:m:s:ms", // range
            // Y axis
            // label
            createDataset(objektList), // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips?
            false // URLs?
    );

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    // y axis right
    plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_RIGHT);
    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setNumberFormatOverride(new NumberFormat() { // show duration
        // values in
        // h:m:s:ms
        @Override
        public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {
            // return new StringBuffer(String.format("%f", number));
            return new StringBuffer(String.format(formatDuration(number)));
        }

        @Override
        public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) {
            // return new StringBuffer(String.format("%f", number));
            return new StringBuffer(String.format(formatDuration(number)));
        }

        @Override
        public Number parse(String source, ParsePosition parsePosition) {
            return null;
        }
    });

    // disable bar outlines...
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator("{1} "
            + translationService.translate("%dashboard.table.label.duration.axis.duration", CONTRIBUTOR_URI)
            + ": {2}ms", NumberFormat.getInstance()));
    renderer.setDrawBarOutline(false);
    renderer.setMaximumBarWidth(.15);
    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(1.57));

    Color color = toAwtColor(ColorConstants.COLOR_BLUE);
    final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, color, 0, 0, color);
    renderer.setSeriesPaint(0, gp0);

    chartComposite = new ChartComposite(parent, SWT.EMBEDDED);
    chartComposite.setSize(800, 800);
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
    chartComposite.setLayoutData(data);
    chartComposite.setHorizontalAxisTrace(false);
    chartComposite.setVerticalAxisTrace(false);
    chartComposite.setChart(chart);
    chartComposite.pack(true);
    chartComposite.setVisible(true);
    chartComposite.forceRedraw();
    parent.layout();
}

From source file:gg.view.overview.IncomeExpensesTopComponent.java

/** Displays the total income vs expenses for the current month */
public void displayData() {
    log.info("Income vs Expenses graph computed and displayed");

    // Display hourglass cursor
    Utilities.changeCursorWaitStatus(true);

    // Create a dataset (the dataset will contain the plotted values)
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    // Create an empty chart
    JFreeChart chart = ChartFactory.createBarChart("", // chart title
            "", // x axis label
            NbBundle.getMessage(IncomeExpensesTopComponent.class, "IncomeExpensesTopComponent.Amount"), // y axis label
            dataset, // data displayed in the chart
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips
            false // urls
    );//from ww  w.ja v  a2s  .  c  om

    // Update the chart color
    chart.setBackgroundPaint(jPanelIncomeExpenses.getBackground());
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);

    // Set the orientation of the categories on the domain axis (X axis)
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD);

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

    // Set the bar renderer
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setMaximumBarWidth(0.1);

    GradientPaint gradientPaint = new GradientPaint(0.0f, 0.0f, new Color(49, 106, 196), 0.0f, 0.0f,
            Color.LIGHT_GRAY);
    renderer.setSeriesPaint(0, gradientPaint);

    // Create a period for the current month
    LocalDate today = new LocalDate();
    Period currentMonth = new Period(Periods.getAdjustedStartDate(today, PeriodType.MONTH),
            Periods.getAdjustedEndDate(today, PeriodType.MONTH), PeriodType.MONTH);

    // Fill the dataset
    List<Currency> currencies = Wallet.getInstance().getActiveCurrencies();
    for (Currency currency : currencies) {
        // Filter on the currency and on the current month
        SearchCriteria searchCriteria = new SearchCriteria(currency, null, currentMonth, null, null, null,
                false);

        // Get income
        BigDecimal currencyIncome = Datamodel.getIncome(searchCriteria);
        currencyIncome = currencyIncome.setScale(2, RoundingMode.HALF_EVEN);

        // Get expenses
        BigDecimal currencyExpenses = Datamodel.getExpenses(searchCriteria).abs();
        currencyExpenses = currencyExpenses.setScale(2, RoundingMode.HALF_EVEN);

        // Plot income and expenses for the current month and for the current currency on the chart
        dataset.addValue(currencyIncome, currency.getName(),
                NbBundle.getMessage(IncomeExpensesTopComponent.class, "IncomeExpensesTopComponent.Income",
                        new Object[] { currency }));

        dataset.addValue(currencyExpenses, currency.getName(),
                NbBundle.getMessage(IncomeExpensesTopComponent.class, "IncomeExpensesTopComponent.Expenses",
                        new Object[] { currency }));
    }

    // Create the chart panel that contains the chart
    ChartPanel chartPanel = new ChartPanel(chart);

    // Display the chart
    jPanelIncomeExpenses.removeAll();
    jPanelIncomeExpenses.add(chartPanel, BorderLayout.CENTER);

    // Display the normal cursor
    Utilities.changeCursorWaitStatus(false);
}

From source file:vista.DestinosMasConsultados.java

public void iniciarGraficos(CategoryDataset dataset) {
    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Paises mas consultados", // chart title
            "Paises", // domain axis label
            "Cantidad de consultas", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/*from w  w  w .j a  va 2  s  .  c  om*/

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

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

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

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

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

    // set up gradient paints for series...
    final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray);
    final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray);
    final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray);
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

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

    ChartPanel chartFinal = new ChartPanel(chart);
    chartFinal.setSize(new Dimension(600, 400));

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(panelDestinosMasConsultados);
    panelDestinosMasConsultados.setLayout(jPanel1Layout);
    jPanel1Layout
            .setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup().addGap(0, 0, 0).addComponent(chartFinal)
                            .addContainerGap(0, Short.MAX_VALUE)));
    jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup().addGap(0, 0, 0).addComponent(chartFinal)
                    .addContainerGap(0, Short.MAX_VALUE)));

}

From source file:net.sf.jasperreports.chartthemes.spring.EyeCandySixtiesChartTheme.java

@Override
protected JFreeChart createPieChart() throws JRException {
    JFreeChart jfreeChart = super.createPieChart();
    PiePlot piePlot = (PiePlot) jfreeChart.getPlot();
    JRPiePlot jrPiePlot = (JRPiePlot) getPlot();
    boolean isShowLabels = jrPiePlot.getShowLabels() == null ? true : jrPiePlot.getShowLabels();

    if (isShowLabels && piePlot.getLabelGenerator() != null) {
        piePlot.setLabelBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT);
        piePlot.setLabelShadowPaint(ChartThemesConstants.TRANSPARENT_PAINT);
        piePlot.setLabelOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT);
    }//from   w  w w  . j  a v  a  2 s .  co m
    piePlot.setShadowXOffset(5);
    piePlot.setShadowYOffset(10);
    piePlot.setShadowPaint(new GradientPaint(0, getChart().getHeight() / 2, new Color(41, 120, 162), 0,
            getChart().getHeight(), Color.white));
    PieDataset pieDataset = piePlot.getDataset();
    if (pieDataset != null) {
        for (int i = 0; i < pieDataset.getItemCount(); i++) {
            piePlot.setSectionOutlinePaint(pieDataset.getKey(i), ChartThemesConstants.TRANSPARENT_PAINT);
            //makes pie colors darker
            //piePlot.setSectionPaint(pieDataset.getKey(i), GRADIENT_PAINTS[i]);
        }
    }

    piePlot.setCircular(true);
    return jfreeChart;
}

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

private static JFreeChart createChart3(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createStackedBarChart("Public Opinion : Torture of Prisoners",
            "Country", "%", categorydataset, PlotOrientation.HORIZONTAL, false, true, false);
    jfreechart.getTitle().setMargin(2D, 0.0D, 0.0D, 0.0D);
    TextTitle texttitle = new TextTitle("Source: http://news.bbc.co.uk/1/hi/world/6063386.stm",
            new Font("Dialog", 0, 11));
    texttitle.setPosition(RectangleEdge.BOTTOM);
    texttitle.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    texttitle.setMargin(0.0D, 0.0D, 4D, 4D);
    jfreechart.addSubtitle(texttitle);/*from  www.  j  a v a  2s.  c  o m*/
    TextTitle texttitle1 = new TextTitle("(*) Across 27,000 respondents in 25 countries",
            new Font("Dialog", 0, 11));
    texttitle1.setPosition(RectangleEdge.BOTTOM);
    texttitle1.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    texttitle1.setMargin(4D, 0.0D, 2D, 4D);
    jfreechart.addSubtitle(texttitle1);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    LegendItemCollection legenditemcollection = new LegendItemCollection();
    legenditemcollection.add(new LegendItem("Against all torture", null, null, null,
            new java.awt.geom.Rectangle2D.Double(-6D, -3D, 12D, 6D), Color.green));
    legenditemcollection.add(new LegendItem("Some degree permissible", null, null, null,
            new java.awt.geom.Rectangle2D.Double(-6D, -3D, 12D, 6D), Color.red));
    categoryplot.setFixedLegendItems(legenditemcollection);
    categoryplot.setInsets(new RectangleInsets(5D, 5D, 5D, 20D));
    LegendTitle legendtitle = new LegendTitle(categoryplot);
    legendtitle.setPosition(RectangleEdge.BOTTOM);
    jfreechart.addSubtitle(legendtitle);
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setDomainGridlinePaint(Color.white);
    categoryplot.setDomainGridlinesVisible(true);
    categoryplot.setRangeGridlinePaint(Color.white);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setUpperMargin(0.0D);
    BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setDrawBarOutline(false);
    GradientPaint gradientpaint = new GradientPaint(0.0F, 0.0F, Color.green, 0.0F, 0.0F, new Color(0, 64, 0));
    Color color = new Color(0, 0, 0, 0);
    GradientPaint gradientpaint1 = new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, new Color(64, 0, 0));
    barrenderer.setSeriesPaint(0, gradientpaint);
    barrenderer.setSeriesPaint(1, color);
    barrenderer.setSeriesPaint(2, gradientpaint1);
    return jfreechart;
}

From source file:net.sourceforge.atunes.kernel.controllers.stats.StatsDialogController.java

private void setArtistsChart() {
    DefaultCategoryDataset dataset = getDataSet(HandlerProxy.getRepositoryHandler().getMostPlayedArtists(10));
    JFreeChart chart = ChartFactory.createStackedBarChart3D(LanguageTool.getString("ARTIST_MOST_PLAYED"), null,
            null, dataset, PlotOrientation.HORIZONTAL, false, false, false);
    chart.getTitle().setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    chart.setBackgroundPaint(new GradientPaint(0, 0, ColorDefinitions.GENERAL_NON_PANEL_TOP_GRADIENT_COLOR, 0,
            200, ColorDefinitions.GENERAL_NON_PANEL_BOTTOM_GRADIENT_COLOR));
    chart.setPadding(new RectangleInsets(5, 0, 0, 0));
    NumberAxis axis = new NumberAxis();
    axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    axis.setTickLabelFont(new Font(Font.SANS_SERIF, Font.PLAIN, 10));
    chart.getCategoryPlot().setRangeAxis(axis);
    chart.getCategoryPlot().setForegroundAlpha(0.6f);
    chart.getCategoryPlot().getRenderer().setPaint(Color.GREEN);

    ((StatsDialog) frameControlled).getArtistsChart()
            .setIcon(new ImageIcon(chart.createBufferedImage(710, 250)));
}