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

/**
 * Creates and returns a sample overlaid chart.
 * <P>/*from   w w w  .java 2s .  c o m*/
 * Note:  with the introduction of multiple secondary datasets in JFreeChart version 0.9.10,
 * the overlaid chart facility has been removed.  You can achieve the same results using
 * a regular XYPlot with multiple datasets.
 *
 * @return an overlaid chart.
 */
public JFreeChart createOverlaidChart() {

    // create a default chart based on some sample data...
    final String title = this.resources.getString("combined.overlaid.title");
    final String subtitleStr = this.resources.getString("combined.overlaid.subtitle");
    final String domainAxisLabel = this.resources.getString("combined.overlaid.domain");
    final String rangeAxisLabel = this.resources.getString("combined.overlaid.range");

    // create high-low and moving average dataset
    final DefaultHighLowDataset highLowData = DemoDatasetFactory.createHighLowDataset();

    // make an overlaid plot
    final ValueAxis domainAxis = new DateAxis(domainAxisLabel);
    final NumberAxis rangeAxis = new NumberAxis(rangeAxisLabel);
    rangeAxis.setAutoRangeIncludesZero(false);
    final XYItemRenderer renderer1 = new HighLowRenderer();
    renderer1.setToolTipGenerator(new HighLowItemLabelGenerator());

    final XYPlot plot = new XYPlot(highLowData, domainAxis, rangeAxis, renderer1);

    // overlay a moving average dataset
    final XYDataset maData = MovingAverage.createMovingAverage(highLowData, " (Moving Average)",
            5 * 24 * 60 * 60 * 1000L, 5 * 24 * 60 * 60 * 1000L);
    plot.setDataset(1, maData);
    final XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0,000.0")));
    plot.setRenderer(1, renderer2);

    // make the top level JFreeChart object
    final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    // then customise it a little...
    final TextTitle subtitle = new TextTitle(subtitleStr, new Font("SansSerif", Font.BOLD, 12));
    chart.addSubtitle(subtitle);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue));

    return chart;

}

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

/**
 * Creates a horizontally combined chart.
 *
 * @return a horizontally combined chart.
 *//*from  w ww . j a  va 2 s .  c o m*/
public JFreeChart createHorizontallyCombinedChart() {

    // create a default chart based on some sample data...
    final String title = this.resources.getString("combined.horizontal.title");
    final String subtitleStr = this.resources.getString("combined.horizontal.subtitle");
    final String[] domains = this.resources.getStringArray("combined.horizontal.domains");
    final String rangeAxisLabel = this.resources.getString("combined.horizontal.range");

    final TimeSeriesCollection dataset0 = new TimeSeriesCollection();
    final TimeSeries eur = DemoDatasetFactory.createEURTimeSeries();
    dataset0.addSeries(eur);

    final TimeSeriesCollection dataset1 = new TimeSeriesCollection();
    final TimeSeries mav = MovingAverage.createMovingAverage(eur, "EUR/GBP (30 Day MA)", 30, 30);
    dataset1.addSeries(eur);
    dataset1.addSeries(mav);

    final TimeSeriesCollection dataset2 = new TimeSeriesCollection();
    dataset2.addSeries(eur);

    // make a combined range plot
    final NumberAxis valueAxis = new NumberAxis(rangeAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false); // override default
    final CombinedRangeXYPlot parent = new CombinedRangeXYPlot(valueAxis);
    parent.setRenderer(new StandardXYItemRenderer());

    // add subplots
    final int[] weight = { 1, 1, 1 }; // controls space assigned to each subplot

    // add subplot 1...
    final XYPlot subplot1 = new XYPlot(dataset0, new DateAxis(domains[0]), null, new StandardXYItemRenderer());
    parent.add(subplot1, weight[0]);

    // add subplot 2...
    final XYPlot subplot2 = new XYPlot(dataset1, new DateAxis(domains[1]), null, new StandardXYItemRenderer());
    parent.add(subplot2, weight[1]);

    // add subplot 3...
    final XYPlot subplot3 = new XYPlot(dataset2, new DateAxis(domains[2]), null, new XYBarRenderer(0.20));
    parent.add(subplot3, weight[2]);

    // now make the top level JFreeChart
    final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, parent, true);

    // then customise it a little...
    final TextTitle subtitle = new TextTitle(subtitleStr, new Font("SansSerif", Font.BOLD, 12));
    chart.addSubtitle(subtitle);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue));
    return chart;

}

From source file:lucee.runtime.tag.Chart.java

private void setColor(JFreeChart chart) {
    Plot p = chart.getPlot();//from w  w w .  j a  v a 2 s .  c  o m
    if (p instanceof CategoryPlot) {
        CategoryPlot cp = (CategoryPlot) p;

        CategoryItemRenderer renderer = cp.getRenderer();

        Iterator<ChartSeriesBean> cs = _series.iterator();
        //int seriesCount=_series.size();
        ChartSeriesBean csb;
        GradientPaint gp;
        Color c = null;
        Color[] ac;

        int index = 0;
        while (cs.hasNext()) {
            csb = cs.next();
            // more than 1 series
            //if(seriesCount>1) {
            c = csb.getSeriesColor();
            if (c == null) {
                ac = csb.getColorlist();
                if (ac != null && ac.length > 0)
                    c = ac[0];
            }

            //}
            if (c == null)
                continue;
            gp = new GradientPaint(0.0f, 0.0f, c, 0.0f, 0.0f, c);
            renderer.setSeriesPaint(index++, gp);
        }
    } else if (p instanceof XYPlot) {
        XYPlot cp = (XYPlot) p;

        XYItemRenderer renderer = cp.getRenderer();

        Iterator<ChartSeriesBean> cs = _series.iterator();
        //int seriesCount=_series.size();
        ChartSeriesBean csb;
        GradientPaint gp;
        Color c = null;
        Color[] ac;

        int index = 0;
        while (cs.hasNext()) {
            csb = cs.next();
            // more than 1 series
            //if(seriesCount>1) {
            c = csb.getSeriesColor();
            if (c == null) {
                ac = csb.getColorlist();
                if (ac != null && ac.length > 0)
                    c = ac[0];
            }

            //}
            if (c == null)
                continue;
            gp = new GradientPaint(0.0f, 0.0f, c, 0.0f, 0.0f, c);
            renderer.setSeriesPaint(index++, gp);
        }
    }
}

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

/**
 * Creates and returns a sample vertically combined chart.
 *
 * @return a sample vertically combined chart.
 *///from  ww  w  .  j a v  a 2s  .c  om
public JFreeChart createVerticallyCombinedChart() {

    // create a default chart based on some sample data...
    final String title = this.resources.getString("combined.vertical.title");
    final String subtitleStr = this.resources.getString("combined.vertical.subtitle");
    final String domain = this.resources.getString("combined.vertical.domain");
    final String[] ranges = this.resources.getStringArray("combined.vertical.ranges");

    final TimeSeriesCollection dataset0 = new TimeSeriesCollection();
    final TimeSeries eur = DemoDatasetFactory.createEURTimeSeries();
    dataset0.addSeries(eur);

    final TimeSeriesCollection dataset1 = new TimeSeriesCollection();
    final TimeSeries jpy = DemoDatasetFactory.createJPYTimeSeries();
    final TimeSeries mav = MovingAverage.createMovingAverage(jpy, "JPY/GBP (30 Day MA)", 30, 30);
    dataset1.addSeries(jpy);
    dataset1.addSeries(mav);

    final XYDataset dataset2 = DemoDatasetFactory.createHighLowDataset();

    final TimeSeriesCollection dataset3 = new TimeSeriesCollection();
    dataset3.addSeries(eur);

    // make one shared horizontal axis
    final ValueAxis timeAxis = new DateAxis(domain);

    // make a vertically CombinedPlot that will contain the sub-plots
    final CombinedDomainXYPlot multiPlot = new CombinedDomainXYPlot(timeAxis);

    final int[] weight = { 1, 1, 1, 1 }; // control vertical space allocated to each sub-plot

    // add subplot1...
    final XYPlot subplot1 = new XYPlot(dataset0, null, new NumberAxis(ranges[0]), new StandardXYItemRenderer());
    final NumberAxis range1 = (NumberAxis) subplot1.getRangeAxis();
    range1.setTickLabelFont(new Font("Monospaced", Font.PLAIN, 7));
    range1.setLabelFont(new Font("SansSerif", Font.PLAIN, 8));
    range1.setAutoRangeIncludesZero(false);
    multiPlot.add(subplot1, weight[0]);

    // add subplot2...
    final XYPlot subplot2 = new XYPlot(dataset1, null, new NumberAxis(ranges[1]), new StandardXYItemRenderer());
    final NumberAxis range2 = (NumberAxis) subplot2.getRangeAxis();
    range2.setTickLabelFont(new Font("Monospaced", Font.PLAIN, 7));
    range2.setLabelFont(new Font("SansSerif", Font.PLAIN, 8));
    range2.setAutoRangeIncludesZero(false);
    multiPlot.add(subplot2, weight[1]);

    // add subplot3...
    final XYPlot subplot3 = new XYPlot(dataset2, null, new NumberAxis(ranges[2]), null);
    final XYItemRenderer renderer3 = new HighLowRenderer();
    subplot3.setRenderer(renderer3);
    final NumberAxis range3 = (NumberAxis) subplot3.getRangeAxis();
    range3.setTickLabelFont(new Font("Monospaced", Font.PLAIN, 7));
    range3.setLabelFont(new Font("SansSerif", Font.PLAIN, 8));
    range3.setAutoRangeIncludesZero(false);
    multiPlot.add(subplot3, weight[2]);

    // add subplot4...
    final XYPlot subplot4 = new XYPlot(dataset3, null, new NumberAxis(ranges[3]), null);
    final XYItemRenderer renderer4 = new XYBarRenderer();
    subplot4.setRenderer(renderer4);
    final NumberAxis range4 = (NumberAxis) subplot4.getRangeAxis();
    range4.setTickLabelFont(new Font("Monospaced", Font.PLAIN, 7));
    range4.setLabelFont(new Font("SansSerif", Font.PLAIN, 8));
    range4.setAutoRangeIncludesZero(false);
    multiPlot.add(subplot4, weight[3]);

    // now make the top level JFreeChart that contains the CombinedPlot
    final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, multiPlot, true);

    // then customise it a little...
    final TextTitle subtitle = new TextTitle(subtitleStr, new Font("SansSerif", Font.BOLD, 12));
    chart.addSubtitle(subtitle);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue));
    return chart;

}

From source file:ReportGen.java

private void weeklyPreviewOfLate(String residentId) {
    try {/* ww w  .j  a v a  2  s  .c om*/
        exportcounttableexcel.setEnabled(true);
        exportcounttablepdf.setEnabled(true);
        //            exportgraphtoimage.setEnabled(true);

        tableModel = (DefaultTableModel) dataTable.getModel();
        tableModel.getDataVector().removeAllElements();
        tableModel.fireTableDataChanged();
        String str[] = { "Months", "Values" };
        tableModel.setColumnIdentifiers(str);

        ChartPanel chartPanel;
        displaypane.removeAll();
        displaypane.revalidate();
        displaypane.repaint();
        displaypane.setLayout(new BorderLayout());
        //row
        String series1 = "Results";
        //column,
        String days[] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
        String resident = residents.getSelectedItem().toString();

        int value[] = new int[12];
        int c = 0;
        for (String day : days) {
            value[c] = client.getDailyReport("0" + (c + 1), client.getResidentId(resident));
            c++;
        }

        for (int i = 0; i < days.length; i++) {
            tableModel.addRow(new Object[] { days[i], value[i] });
        }
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        dataset.addValue(value[0], series1, days[0]);
        dataset.addValue(value[1], series1, days[1]);
        dataset.addValue(value[2], series1, days[2]);
        dataset.addValue(value[3], series1, days[3]);
        dataset.addValue(value[4], series1, days[4]);
        dataset.addValue(value[5], series1, days[5]);
        dataset.addValue(value[6], series1, days[6]);

        chart = ChartFactory.createBarChart("181 North Place Residences Graph", // chart title
                "Months of the Year 2014", // domain axis label
                "Value", // range axis label
                dataset, // data
                PlotOrientation.VERTICAL, // orientation
                true, // include legend
                true, // tooltips
                false // urls
        );

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

        // get a reference to the plot for further customisation...
        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 org.jfree.chart.axis.CategoryAxis domainAxis = plot.getDomainAxis();
        domainAxis.setCategoryLabelPositions(
                CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
        chartPanel = new ChartPanel(chart);
        displaypane.add(chartPanel, BorderLayout.CENTER);
    } catch (RemoteException ex) {
        //            Logger.getLogger(ReportGen.class.getName()).log(Level.SEVERE, null, ex);
        new MessageDialog().error(this, ex.getMessage());
    }
}

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

/**
 * Creates a combined and overlaid chart.
 * <p>//from w  w  w.jav a 2 s.  com
 * Note: from version 0.9.10, the overlaid chart is no longer supported (you can achieve
 * the same result using a regular XYPlot with multiple datasets and renderers).
 *
 * @return a combined and overlaid chart.
 */
public JFreeChart createCombinedAndOverlaidChart1() {

    // create a default chart based on some sample data...
    final String title = this.resources.getString("combined.combined-overlaid.title");
    final String subtitleStr = this.resources.getString("combined.combined-overlaid.subtitle");
    final String domain = this.resources.getString("combined.combined-overlaid.domain");
    final String[] ranges = this.resources.getStringArray("combined.combined-overlaid.ranges");

    final TimeSeries jpy = DemoDatasetFactory.createJPYTimeSeries();
    final TimeSeries mav = MovingAverage.createMovingAverage(jpy, "30 Day Moving Average", 30, 30);

    final TimeSeriesCollection dataset0 = new TimeSeriesCollection();
    dataset0.addSeries(jpy);

    final TimeSeriesCollection dataset1 = new TimeSeriesCollection();
    dataset1.addSeries(jpy);
    dataset1.addSeries(mav);

    final DefaultHighLowDataset highLowDataset = DemoDatasetFactory.createHighLowDataset();
    final XYDataset highLowDatasetMA = MovingAverage.createMovingAverage(highLowDataset, " (MA)",
            5 * 24 * 60 * 60 * 1000L, 5 * 24 * 60 * 60 * 1000L);

    // make one vertical axis for each (vertical) chart
    final NumberAxis[] valueAxis = new NumberAxis[3];
    for (int i = 0; i < valueAxis.length; i++) {
        valueAxis[i] = new NumberAxis(ranges[i]);
        if (i <= 1) {
            valueAxis[i].setAutoRangeIncludesZero(false); // override default
        }
    }

    // create CombinedPlot...
    final CombinedDomainXYPlot parent = new CombinedDomainXYPlot(new DateAxis(domain));

    final int[] weight = { 1, 2, 2 };

    // add subplot1...
    final XYItemRenderer renderer1 = new StandardXYItemRenderer();
    final XYPlot subplot1 = new XYPlot(dataset0, null, new NumberAxis(ranges[0]), renderer1);
    final NumberAxis axis1 = (NumberAxis) subplot1.getRangeAxis();
    axis1.setTickLabelFont(new Font("Monospaced", Font.PLAIN, 7));
    axis1.setLabelFont(new Font("SansSerif", Font.PLAIN, 8));
    axis1.setAutoRangeIncludesZero(false);
    parent.add(subplot1, weight[0]);

    // add subplot2 (an overlaid plot)...
    final XYPlot subplot2 = new XYPlot(dataset0, null, new NumberAxis(ranges[1]), new StandardXYItemRenderer());
    final NumberAxis axis2 = (NumberAxis) subplot2.getRangeAxis();
    axis2.setTickLabelFont(new Font("Monospaced", Font.PLAIN, 7));
    axis2.setLabelFont(new Font("SansSerif", Font.PLAIN, 8));
    axis2.setAutoRangeIncludesZero(false);
    subplot2.setDataset(1, dataset1);
    subplot2.setRenderer(1, new StandardXYItemRenderer());

    parent.add(subplot2, weight[1]);

    // add subplot3 (an overlaid plot)...
    final XYItemRenderer renderer3 = new HighLowRenderer();
    final XYPlot subplot3 = new XYPlot(highLowDataset, null, new NumberAxis(ranges[2]), renderer3);
    final NumberAxis axis3 = (NumberAxis) subplot3.getRangeAxis();
    axis3.setTickLabelFont(new Font("Monospaced", Font.PLAIN, 7));
    axis3.setLabelFont(new Font("SansSerif", Font.PLAIN, 8));
    axis3.setAutoRangeIncludesZero(false);
    subplot3.setDataset(1, highLowDatasetMA);
    subplot3.setRenderer(1, new StandardXYItemRenderer());

    parent.add(subplot3, weight[2]);

    // now create the master JFreeChart object
    final JFreeChart chart = new JFreeChart(title, new Font("SansSerif", Font.BOLD, 12), parent, true);

    // then customise it a little...
    final TextTitle subtitle = new TextTitle(subtitleStr, new Font("SansSerif", Font.BOLD, 10));
    chart.addSubtitle(subtitle);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue));
    return chart;

}

From source file:org.jfree.eastwood.ChartEngine.java

/**
 * Process the string which contains an encoding for the chart background
 * fill, and apply it to the chart.//w  w w  .  j av  a2  s .c  o  m
 *
 * @param spec  the fill specification.
 * @param chart  the chart.
 */
private static void processFillSpec(String spec, JFreeChart chart) {
    if (spec.startsWith("bg")) {
        // do the chart background
        spec = spec.substring(3);
        if (spec.startsWith("s")) {
            spec = spec.substring(2);
            Color c = parseColor(spec);
            chart.setBackgroundPaint(c);
        } else if (spec.startsWith("lg")) {
            spec = spec.substring(3);
            String[] args = breakString(spec, ',');
            int angle = Integer.parseInt(args[0]);
            Color c0 = parseColor(args[1]);
            float f0 = Float.parseFloat(args[2]);
            Color c1 = parseColor(args[3]);
            float f1 = Float.parseFloat(args[4]);
            if (chart.getPlot() instanceof GXYPlot) {
                GXYPlot gxyplot = (GXYPlot) chart.getPlot();
                gxyplot.setF0(f0);
                gxyplot.setF1(f1);
                gxyplot.setAngle(Math.PI / 180.0 * angle);
                gxyplot.setBackgroundPaint(new GradientPaint(0.0f, 0.0f, c0, 0.0f, 0.0f, c1));
            }
        }
    } else if (spec.startsWith("c")) {
        // do the plot background
        spec = spec.substring(2);
        if (spec.startsWith("s")) {
            spec = spec.substring(2);
            Color c = parseColor(spec);
            chart.getPlot().setBackgroundPaint(c);
        } else if (spec.startsWith("lg")) {
            spec = spec.substring(3);
            String[] args = breakString(spec, ',');
            int angle = Integer.parseInt(args[0]);
            Color c0 = parseColor(args[1]);
            float f0 = Float.parseFloat(args[2]);
            Color c1 = parseColor(args[3]);
            float f1 = Float.parseFloat(args[4]);
            if (chart.getPlot() instanceof GXYPlot) {
                GXYPlot gxyplot = (GXYPlot) chart.getPlot();
                gxyplot.setF0(f0);
                gxyplot.setF1(f1);
                gxyplot.setAngle(Math.PI / 180.0 * angle);
                gxyplot.setBackgroundPaint(new GradientPaint(0.0f, 0.0f, c0, 0.0f, 0.0f, c1));
            }
        } else {
            throw new RuntimeException("'c' background fill not implemented yet.");
        }
    } else {
        throw new RuntimeException("Bad fill specification: " + spec);
    }
}

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

/**
 * Displays an XY chart that is periodically updated by a background thread.  This is to
 * demonstrate the event notification system that automatically updates charts as required.
 *
 * @return a chart./*ww  w  .ja v  a2 s  . co m*/
 */
public JFreeChart createCombinedAndOverlaidDynamicXYChart() {

    // chart title and axis labels...
    final String title = this.resources.getString("combined.dynamic.title");
    final String subtitleStr = this.resources.getString("combined.dynamic.subtitle");
    final String domainAxisLabel = this.resources.getString("combined.dynamic.domain");
    final String[] ranges = this.resources.getStringArray("combined.dynamic.ranges");

    // setup sample base 2-series dataset
    final SampleXYDataset data = new SampleXYDataset();

    // create some SubSeriesDatasets and CombinedDatasets to test events
    final XYDataset series0 = new SubSeriesDataset(data, 0);
    final XYDataset series1 = new SubSeriesDataset(data, 1);

    final CombinedDataset combinedData = new CombinedDataset();
    combinedData.add(series0);
    combinedData.add(series1);

    // create common time axis
    final NumberAxis timeAxis = new NumberAxis(domainAxisLabel);
    timeAxis.setTickMarksVisible(true);
    timeAxis.setAutoRangeIncludesZero(false);

    // make one vertical axis for each (vertical) chart
    final NumberAxis[] valueAxis = new NumberAxis[4];
    for (int i = 0; i < valueAxis.length; i++) {
        valueAxis[i] = new NumberAxis(ranges[i]);
        valueAxis[i].setAutoRangeIncludesZero(false);
    }

    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(timeAxis);

    // add subplot1...
    final XYItemRenderer renderer0 = new StandardXYItemRenderer();
    final XYPlot subplot0 = new XYPlot(series0, null, valueAxis[0], renderer0);
    plot.add(subplot0, 1);

    // add subplot2...
    final XYItemRenderer renderer1 = new StandardXYItemRenderer();
    final XYPlot subplot1 = new XYPlot(series1, null, valueAxis[1], renderer1);
    plot.add(subplot1, 1);

    // add subplot3...
    final XYPlot subplot2 = new XYPlot(series0, null, valueAxis[2], new StandardXYItemRenderer());
    subplot2.setDataset(1, series1);
    subplot2.setRenderer(1, new StandardXYItemRenderer());
    plot.add(subplot2, 1);

    // add subplot4...
    final XYItemRenderer renderer3 = new StandardXYItemRenderer();
    final XYPlot subplot3 = new XYPlot(data, null, valueAxis[3], renderer3);
    plot.add(subplot3, 1);

    final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    // then customise it a little...
    final TextTitle subtitle = new TextTitle(subtitleStr, new Font("SansSerif", Font.BOLD, 12));
    chart.addSubtitle(subtitle);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.cyan));

    // setup thread to update base Dataset
    final SampleXYDatasetThread update = new SampleXYDatasetThread(data);
    final Thread thread = new Thread(update);
    thread.start();

    return chart;

}

From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java

private byte[] generateLayeredBarChart(CategoryDataset dataset, int width, int height) {
    JFreeChart chart = ChartFactory.createBarChart(null, // chart title
            null, // domain axis label
            null, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // the plot orientation
            true, // legend
            true, // tooltips
            false // urls
    );/*from   www.  jav a 2 s  . c o m*/

    // set background
    chart.setBackgroundPaint(parseColor(statsManager.getChartBackgroundColor()));

    // set chart border
    chart.setPadding(new RectangleInsets(10, 5, 5, 5));
    chart.setBorderVisible(true);
    chart.setBorderPaint(parseColor("#cccccc"));

    // set anti alias
    chart.setAntiAlias(true);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    // disable bar outlines...
    LayeredBarRenderer renderer = new LayeredBarRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setSeriesBarWidth(0, .6);
    renderer.setSeriesBarWidth(1, .8);
    renderer.setSeriesBarWidth(2, 1.0);
    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);

    CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);

    BufferedImage img = chart.createBufferedImage(width, height);
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        ImageIO.write(img, "png", out);
    } catch (IOException e) {
        log.warn("Error occurred while generating SiteStats chart image data", e);
    }
    return out.toByteArray();
}

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

/**
 * Creates a gantt chart./*  w  w w  .  j  a v  a  2s.  co  m*/
 *
 * @return a gantt chart.
 */
public JFreeChart createGanttChart() {

    final String title = this.resources.getString("gantt.task.title");
    final String domain = this.resources.getString("gantt.task.domain");
    final String range = this.resources.getString("gantt.task.range");

    final IntervalCategoryDataset data = createGanttDataset1();

    final JFreeChart chart = ChartFactory.createGanttChart(title, domain, range, data, true, true, false);

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

}