Example usage for org.jfree.chart.plot PiePlot setBackgroundPaint

List of usage examples for org.jfree.chart.plot PiePlot setBackgroundPaint

Introduction

In this page you can find the example usage for org.jfree.chart.plot PiePlot setBackgroundPaint.

Prototype

public void setBackgroundPaint(Paint paint) 

Source Link

Document

Sets the background color of the plot area and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:RMOS.PieChart.java

/**
 * Creates a chart.// www.j a  v a2  s  .  com
 *
 * @param dataset  the dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(PieDataset dataset) {

    JFreeChart chart = ChartFactory.createPieChart("Eco Systems Statistics", // chart title
            dataset, // data
            false, // no legend
            true, // tooltips
            false // no URL generation
    );

    // set a custom background for the chart
    chart.setBackgroundPaint(
            new GradientPaint(new Point(0, 0), new Color(20, 20, 20), new Point(400, 200), Color.DARK_GRAY));

    // customise the title position and font
    TextTitle t = chart.getTitle();
    t.setHorizontalAlignment(HorizontalAlignment.LEFT);
    t.setPaint(new Color(240, 240, 240));
    t.setFont(new Font("Arial", Font.BOLD, 26));

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setInteriorGap(0.04);
    plot.setOutlineVisible(false);

    plot.setSectionPaint(f1.getStationInGroup().get(1), Color.blue);
    plot.setSectionPaint(f1.getStationInGroup().get(1), Color.GREEN);

    // use gradients and white borders for the section colours
    /*plot.setSectionPaint("Others", createGradientPaint(new Color(200, 200, 255), Color.BLUE));
    plot.setSectionPaint("Samsung", createGradientPaint(new Color(255, 200, 200), Color.RED));
    plot.setSectionPaint("Apple", createGradientPaint(new Color(200, 255, 200), Color.GREEN));
    plot.setSectionPaint("Nokia", createGradientPaint(new Color(200, 255, 200), Color.YELLOW));*/
    plot.setBaseSectionOutlinePaint(Color.WHITE);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f));

    // customise the section label appearance
    plot.setLabelFont(new Font("Courier New", Font.BOLD, 20));
    plot.setLabelLinkPaint(Color.WHITE);
    plot.setLabelLinkStroke(new BasicStroke(2.0f));
    plot.setLabelOutlineStroke(null);
    plot.setLabelPaint(Color.WHITE);
    plot.setLabelBackgroundPaint(null);

    // add a subtitle giving the data source
    TextTitle source = new TextTitle("Source: Eco Recycle Station", new Font("Courier New", Font.PLAIN, 12));
    source.setPaint(Color.WHITE);
    source.setPosition(RectangleEdge.BOTTOM);
    source.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    chart.addSubtitle(source);
    return chart;

}

From source file:UserInterface.PublisherRole.ViewUserHabitsJPanel.java

private static JFreeChart createChart(PieDataset dataset) {

    JFreeChart chart = ChartFactory.createPieChart("User Habits", // chart title
            dataset, // data
            false, // no legend
            true, // tooltips
            false // no URL generation
    );//from   w w w  .jav  a2s  . c o m

    // set a custom background for the chart
    chart.setBackgroundPaint(
            new GradientPaint(new Point(0, 0), new Color(20, 20, 20), new Point(400, 200), Color.DARK_GRAY));

    // customise the title position and font
    TextTitle t = chart.getTitle();
    t.setHorizontalAlignment(HorizontalAlignment.LEFT);
    t.setPaint(new Color(240, 240, 240));
    t.setFont(new Font("Arial", Font.BOLD, 26));

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setInteriorGap(0.04);
    plot.setOutlineVisible(false);

    // use gradients and white borders for the section colours
    plot.setSectionPaint("Others", createGradientPaint(new Color(200, 200, 255), Color.BLUE));
    plot.setSectionPaint("Samsung", createGradientPaint(new Color(255, 200, 200), Color.RED));
    plot.setSectionPaint("Apple", createGradientPaint(new Color(200, 255, 200), Color.GREEN));
    plot.setSectionPaint("Nokia", createGradientPaint(new Color(200, 255, 200), Color.YELLOW));
    plot.setBaseSectionOutlinePaint(Color.WHITE);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f));

    // customise the section label appearance
    plot.setLabelFont(new Font("Courier New", Font.BOLD, 20));
    plot.setLabelLinkPaint(Color.WHITE);
    plot.setLabelLinkStroke(new BasicStroke(2.0f));
    plot.setLabelOutlineStroke(null);
    plot.setLabelPaint(Color.WHITE);
    plot.setLabelBackgroundPaint(null);

    // add a subtitle giving the data source
    TextTitle source = new TextTitle(" ", new Font("Courier New", Font.PLAIN, 12));
    source.setPaint(Color.WHITE);
    source.setPosition(RectangleEdge.BOTTOM);
    source.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    chart.addSubtitle(source);
    return chart;

}

From source file:utils.Graphs.java

public static File generate(File baseFolder, String titles[], int[] values, Color backgroundColor) {
    DefaultPieDataset dataset = new DefaultPieDataset();

    // add our data values
    int i = -1;/*from  www  .  ja  v  a 2  s.c  o m*/
    for (String title : titles) {
        i++;
        dataset.setValue(title, values[i]);
    }

    final JFreeChart chart =
            //                ChartFactory.createPieChart("", dataset, true, true, false);

            ChartFactory.createPieChart("", // chart title
                    dataset, // data
                    true, // include legend
                    true, false);

    PiePlot plot = (PiePlot) chart.getPlot();
    //PiePlot3D plot = (PiePlot3D) chart.getPlot();
    //plot.setStartAngle(290);
    plot.setStartAngle(45);
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.5f);

    //        final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(backgroundColor);

    //        plot.setLegendLabelGenerator(
    //        new StandardPieSectionLabelGenerator("{0} {2}"));

    chart.setBorderVisible(false);
    chart.getPlot().setOutlineVisible(false);
    chart.getLegend().setFrame(BlockBorder.NONE);

    // get the same background
    chart.setBackgroundPaint(backgroundColor);
    chart.getLegend().setBackgroundPaint(backgroundColor);

    // hide the shadow effects
    plot.setShadowXOffset(0);
    plot.setShadowYOffset(0);

    //chart.getLegend().setVisible(false);

    plot.setCircular(true);
    //plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {2}", NumberFormat.getNumberInstance(), NumberFormat
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{2}", NumberFormat.getNumberInstance(),
            NumberFormat.getPercentInstance()));
    plot.setNoDataMessage("No data found.");

    Color greenColor = new Color(0x8FBC0C);
    Color redColor = new Color(0xFF0000);
    //Color redColor = new Color(0xDA6022);

    plot.setSectionPaint(0, greenColor);
    plot.setSectionPaint(1, redColor);
    plot.setSectionOutlinesVisible(true);

    final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
    final File file = new File(baseFolder, "chart.png");
    try {
        ChartUtilities.saveChartAsPNG(file, chart, 200, 160, info);
    } catch (IOException ex) {
        Logger.getLogger(Graphs.class.getName()).log(Level.SEVERE, null, ex);
    }
    //        
    ////        final ChartPanel chartPanel = new ChartPanel(chart, true);
    //       final ChartPanel chartPanel = new ChartPanel(chart, true);
    //        chartPanel.setMinimumDrawWidth(0);
    //        chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE);
    //        chartPanel.setMinimumDrawHeight(0);
    //        chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE);
    //        JDialog dialog = new JDialog();
    //        dialog.add(chartPanel);
    //        dialog.setLayout(new GridLayout(1, 1));
    //        dialog.setSize(400, 200);
    //        dialog.setVisible(true);

    return file;
}

From source file:com.tonbeller.jpivot.chart.ChartFactory.java

/**
 * Creates a chart containing multiple pie charts, from a TableDataset.
 *
 * @param title  the chart title./*from ww  w .j a  va 2  s.co  m*/
 * @param data  the dataset for the chart.
 * @param extractType  <code>PER_ROW</code> or <code>PER_COLUMN</code> (defined in 
 *                     {@link PiePlot}).
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param urls  configure chart to generate URLs?
 *
 * @return a pie chart.
 */
public static JFreeChart createPieChart(String title, java.awt.Font titleFont, CategoryDataset data,
        TableOrder order, boolean legend, boolean tooltips, boolean urls, PieURLGenerator urlGenerator) {

    MultiplePiePlot plot = new MultiplePiePlot(data);
    plot.setDataExtractOrder(order);

    PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
    //pp.setInsets(new Insets(0, 5, 5, 5));
    pp.setBackgroundPaint(null);
    // no outline around each piechart
    pp.setOutlineStroke(null);
    //plot.setOutlineStroke(null);
    PieToolTipGenerator tooltipGenerator = null;
    if (tooltips) {
        tooltipGenerator = new StandardPieToolTipGenerator();
    }

    //PieURLGenerator urlGenerator = null;
    if (!urls) {
        urlGenerator = null;
    }

    pp.setToolTipGenerator(tooltipGenerator);
    pp.setLabelGenerator(null);
    pp.setURLGenerator(urlGenerator);

    JFreeChart chart = new JFreeChart(title, titleFont, plot, legend);

    return chart;

}

From source file:com.ewcms.plugin.report.generate.service.chart.ChartGenerationService.java

/**
 * /*from   w  ww . j  ava 2  s.com*/
 *
 * @param title 
 * @param titleFont 
 * @param data ??
 * @param order
 * @param legend 
 * @param tooltips ????
 * @param urls ??URL
 * @param urlGenerator
 *
 * @return 
 */
public static JFreeChart createPieChart(String title, java.awt.Font titleFont, CategoryDataset data,
        TableOrder order, boolean legend, boolean tooltips, boolean urls, PieURLGenerator urlGenerator) {
    MultiplePiePlot plot = new MultiplePiePlot(data);
    plot.setDataExtractOrder(order);

    PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
    // pp.setInsets(new Insets(0, 5, 5, 5));
    pp.setBackgroundPaint(null);
    pp.setOutlineStroke(null);
    // plot.setOutlineStroke(null);
    PieToolTipGenerator tooltipGenerator = null;
    if (tooltips) {
        tooltipGenerator = new StandardPieToolTipGenerator();
    }

    // PieURLGenerator urlGenerator = null;
    if (!urls) {
        urlGenerator = null;
    }

    pp.setToolTipGenerator(tooltipGenerator);
    pp.setLabelGenerator(null);
    pp.setURLGenerator(urlGenerator);

    JFreeChart chart = new JFreeChart(title, titleFont, plot, legend);

    return chart;

}

From source file:org.openmrs.module.usagestatistics.web.view.chart.FoundByChartView.java

@Override
protected JFreeChart createChart(Map<String, Object> model, HttpServletRequest request) {
    UsageStatisticsService svc = Context.getService(UsageStatisticsService.class);
    int[] stats = svc.getFoundByStats(getFromDate(), getUntilInclusiveDate(), getLocation(), getUsageFilter());

    String labelLink = ContextProvider.getMessage("usagestatistics.foundBy.directLink");
    String labelId = ContextProvider.getMessage("usagestatistics.foundBy.idSearch");
    String labelName = ContextProvider.getMessage("usagestatistics.foundBy.nameSearch");

    double total = stats[0];
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue(labelLink, 100.0 * stats[1] / total);
    dataset.setValue(labelId, 100.0 * stats[2] / total);
    dataset.setValue(labelName, 100.0 * stats[3] / total);

    JFreeChart chart = ChartFactory.createPieChart(null, dataset, false, false, false);

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setInteriorGap(0.0);//from www.  j av  a2 s .  c  om
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2})"));
    plot.setLabelFont(getFont());

    return chart;
}

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

/**
 * Creates a sample chart with the given dataset.
 * //from w w  w.  j  a  v  a2  s .  co m
 * @param dataset  the dataset.
 * 
 * @return A sample chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {
    final JFreeChart chart = ChartFactory.createMultiplePieChart("Multiple Pie Chart", // chart title
            dataset, // dataset
            TableOrder.BY_COLUMN, true, // include legend
            true, false);
    final MultiplePiePlot plot = (MultiplePiePlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setOutlineStroke(new BasicStroke(1.0f));
    final JFreeChart subchart = plot.getPieChart();
    final PiePlot p = (PiePlot) subchart.getPlot();
    p.setBackgroundPaint(null);
    p.setOutlineStroke(null);
    p.setLabelGenerator(new StandardPieItemLabelGenerator("{0} ({2})", NumberFormat.getNumberInstance(),
            NumberFormat.getPercentInstance()));
    p.setMaximumLabelWidth(0.35);
    p.setLabelFont(new Font("SansSerif", Font.PLAIN, 9));
    p.setInteriorGap(0.30);
    return chart;
}

From source file:lu.lippmann.cdb.datasetview.tabs.PieChartTabView.java

/**
 * Constructor.//from   w  ww . j a  va 2 s. c  om
 */
public PieChartTabView() {
    super();

    this.pieDataset = new DefaultPieDataset();
    this.pieChart = ChartFactory.createPieChart("", this.pieDataset, true, true, true);
    final PiePlot plot = (PiePlot) this.pieChart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    this.chartPanel = new ChartPanel(this.pieChart, true);
}

From source file:WeeklyReport.Sections.Commodities.java

private JFreeChart commodityChart() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    Map<Double, String> mp = new CargoTypeData().quotesByCommodityCBM();
    mp.entrySet().stream().forEach((mapEntry) -> {
        dataset.setValue(mapEntry.getValue(), mapEntry.getKey());
    });/*from   w ww  . j  a v  a  2  s.c  o m*/
    JFreeChart pieChart = ChartFactory.createPieChart3D("Commodities Quoted by Cubic Meter", dataset, true,
            true, false);

    PiePlot plot = (PiePlot) pieChart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);

    PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} cbm ({2})",
            new DecimalFormat("0.000"), new DecimalFormat("0%"));
    plot.setLabelGenerator(gen);

    return pieChart;
}

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

/**
 * Default constructor./*from w w  w  .j  a  v a 2 s  .c  o  m*/
 *
 * @param title  the frame title.
 */
public PieChartDemo4(final String title) {

    super(title);
    final PieDataset dataset = createDataset(14);

    // create the chart...
    final JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 4", // chart title
            dataset, // dataset
            false, // include legend
            true, false);

    // set the background color for the chart...
    chart.setBackgroundPaint(new Color(222, 222, 255));
    final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setCircular(true);
    plot.setLabelGenerator(new StandardPieItemLabelGenerator("{0} = {2}", NumberFormat.getNumberInstance(),
            NumberFormat.getPercentInstance()));
    plot.setNoDataMessage("No data available");

    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

    final Rotator rotator = new Rotator(plot);
    rotator.start();

}