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

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

Introduction

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

Prototype

public PiePlot(PieDataset dataset) 

Source Link

Document

Creates a plot that will draw a pie chart for the specified dataset.

Usage

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

private static JFreeChart createPieChart() {
    DefaultPieDataset defaultpiedataset = new DefaultPieDataset();
    defaultpiedataset.setValue("Engineering", 43.200000000000003D);
    defaultpiedataset.setValue("Research", 13.199999999999999D);
    defaultpiedataset.setValue("Advertising", 20.899999999999999D);
    PiePlot pieplot = new PiePlot(defaultpiedataset);
    pieplot.setBackgroundPaint(null);/*from ww w.  j a va  2 s.  c o  m*/
    pieplot.setOutlinePaint(null);
    pieplot.setBaseSectionOutlinePaint(Color.white);
    pieplot.setBaseSectionOutlineStroke(new BasicStroke(2.0F));
    pieplot.setLabelFont(new Font("Dialog", 0, 18));
    pieplot.setMaximumLabelWidth(0.25D);
    JFreeChart jfreechart = new JFreeChart(pieplot);
    jfreechart.setBackgroundPaint(null);
    jfreechart.removeLegend();
    jfreechart.setPadding(RectangleInsets.ZERO_INSETS);
    return jfreechart;
}

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

private static JFreeChart createPieChart(PieDataset dataset, PieDataset previousDataset) {
    final boolean greenForIncrease = true;
    final boolean subTitle = true;
    final boolean showDifference = true;
    int percentDiffForMaxScale = 20;
    PiePlot plot = new PiePlot(dataset);
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator());
    plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));

    if (tooltips) {
        plot.setToolTipGenerator(new StandardPieToolTipGenerator());
    }/*from   w  ww.  ja  v a2  s.c  o  m*/
    if (urls) {
        plot.setURLGenerator(new StandardPieURLGenerator());
    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
    List<Comparable> keys = dataset.getKeys();
    DefaultPieDataset series = null;
    if (showDifference) {
        series = new DefaultPieDataset();
    }

    double colorPerPercent = 255.0 / percentDiffForMaxScale;
    for (@SuppressWarnings("rawtypes")
    Comparable key : keys) {
        Number newValue = dataset.getValue(key);
        Number oldValue = previousDataset.getValue(key);

        if (oldValue == null) {
            if (greenForIncrease) {
                plot.setSectionPaint(key, Color.green);
            } else {
                plot.setSectionPaint(key, Color.red);
            }
            if (showDifference) {
                series.setValue(key + " (+100%)", newValue);
            }
        } else {
            double percentChange = (newValue.doubleValue() / oldValue.doubleValue() - 1.0) * 100.0;
            double shade = (Math.abs(percentChange) >= percentDiffForMaxScale ? 255
                    : Math.abs(percentChange) * colorPerPercent);
            if (greenForIncrease && newValue.doubleValue() > oldValue.doubleValue()
                    || !greenForIncrease && newValue.doubleValue() < oldValue.doubleValue()) {
                plot.setSectionPaint(key, new Color(0, (int) shade, 0));
            } else {
                plot.setSectionPaint(key, new Color((int) shade, 0, 0));
            }
            if (showDifference) {
                series.setValue(
                        key + " (" + (percentChange >= 0 ? "+" : "")
                                + NumberFormat.getPercentInstance().format(percentChange / 100.0) + ")",
                        newValue);
            }
        }
    }

    if (showDifference) {
        plot.setDataset(series);
    }

    JFreeChart chart = new JFreeChart("Pie Chart Demo 2", JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

    if (subTitle) {
        TextTitle subtitle = null;
        subtitle = new TextTitle("Bright " + (greenForIncrease ? "red" : "green") + "=change >=-"
                + percentDiffForMaxScale + "%, Bright " + (!greenForIncrease ? "red" : "green") + "=change >=+"
                + percentDiffForMaxScale + "%", new Font("SansSerif", Font.PLAIN, 10));
        chart.addSubtitle(subtitle);
    }
    plot.setNoDataMessage("No data available");

    return chart;

}

From source file:org.jfree.graphics2d.demo.SVGChartWithAnnotationsDemo1.java

private static JFreeChart createPieChart() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("Engineering", 43.2);
    dataset.setValue("Research", 13.2);
    dataset.setValue("Advertising", 20.9);
    PiePlot plot = new PiePlot(dataset);
    plot.setBackgroundPainter(null);/* w w w . j  ava  2s  . c om*/
    plot.setBorderPainter(null);
    plot.setBaseSectionOutlinePaint(Color.white);
    plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f));
    plot.setLabelFont(new Font("Dialog", Font.PLAIN, 18));
    plot.setMaximumLabelWidth(0.25);
    JFreeChart chart = new JFreeChart(plot);
    chart.setBackgroundPainter(null);
    chart.removeLegend();
    chart.setPadding(RectangleInsets.ZERO_INSETS);
    return chart;
}

From source file:genj.chart.Chart.java

/**
 * Constructor for a pie chart with one series of data containing the
 * values for the pieces of the pie.//from w ww .  ja va  2  s .  c om
 * @param title the title of the pie chart
 * @param series one series defining the pie/pieces
 * @param categories a category string per index in series
 * @param legend whether to show a legend
 */
public Chart(String title, IndexedSeries series, String[] categories, boolean legend) {

    PiePlot plot = new PiePlot(IndexedSeries.asPieDataset(series, categories));
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {1}"));
    plot.setInsets(new RectangleInsets(0, 5, 5, 10));

    init(title, plot, legend);

}

From source file:probe.com.view.body.quantcompare.PieChart.java

private String initPieChart(int width, int height, String title) {
    DefaultPieDataset dataset = new DefaultPieDataset();
    for (int x = 0; x < labels.length; x++) {
        dataset.setValue(labels[x], values[x]);

    }//from  www  .  j  a v a2s.  c o m
    PiePlot plot = new PiePlot(dataset);
    plot.setNoDataMessage("No data available");
    plot.setCircular(true);

    plot.setLabelGap(0);

    plot.setLabelFont(new Font("Verdana", Font.BOLD, 10));
    plot.setLabelGenerator(new PieSectionLabelGenerator() {

        @Override
        public String generateSectionLabel(PieDataset pd, Comparable cmprbl) {
            return valuesMap.get(cmprbl.toString());
        }

        @Override
        public AttributedString generateAttributedSectionLabel(PieDataset pd, Comparable cmprbl) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    });
    plot.setSimpleLabels(true);

    plot.setLabelBackgroundPaint(null);
    plot.setLabelShadowPaint(null);
    plot.setLabelPaint(Color.WHITE);
    plot.setLabelOutlinePaint(null);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setInteriorGap(0);
    plot.setShadowPaint(Color.WHITE);
    plot.setOutlineVisible(false);
    plot.setBaseSectionOutlinePaint(Color.WHITE);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(1.2f));
    plot.setInteriorGap(0.05);
    for (String label : labels) {
        plot.setSectionPaint(label, defaultKeyColorMap.get(label));
    }

    JFreeChart chart = new JFreeChart(plot);
    //        chart.setTitle(new TextTitle(title, new Font("Verdana", Font.BOLD, 13)));
    chart.setBorderPaint(null);
    chart.setBackgroundPaint(null);
    chart.getLegend().setFrame(BlockBorder.NONE);
    chart.getLegend().setItemFont(new Font("Verdana", Font.PLAIN, 10));
    String imgUrl = saveToFile(chart, width, height);

    return imgUrl;

}

From source file:probe.com.view.body.quantdatasetsoverview.diseasegroupsfilters.interactivepiechartfilters.JfreeDivaPieChartFilter.java

private String initPieChart(int width, int height) {
    DefaultPieDataset dataset = new DefaultPieDataset();
    for (int x = 0; x < labels.length; x++) {
        dataset.setValue(labels[x], new Double(values[x]));

    }//from   www  .  j a  v  a2 s .co  m
    plot = new PiePlot(dataset);
    plot.setNoDataMessage("No data available");
    plot.setCircular(true);

    plot.setLabelGap(0);

    plot.setLabelFont(new Font("Verdana", Font.BOLD, 15));
    plot.setLabelGenerator(new PieSectionLabelGenerator() {

        @Override
        public String generateSectionLabel(PieDataset pd, Comparable cmprbl) {
            return valuesMap.get(cmprbl.toString());
        }

        @Override
        public AttributedString generateAttributedSectionLabel(PieDataset pd, Comparable cmprbl) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    });
    plot.setSimpleLabels(true);

    plot.setLabelBackgroundPaint(null);
    plot.setLabelShadowPaint(null);
    plot.setLabelPaint(Color.WHITE);
    plot.setLabelOutlinePaint(null);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setInteriorGap(0);
    plot.setShadowPaint(Color.WHITE);
    plot.setOutlineVisible(false);
    plot.setBaseSectionOutlinePaint(Color.WHITE);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(1.2f));
    plot.setInteriorGap(0.05);
    for (String label : labels) {
        plot.setSectionPaint(label, defaultKeyColorMap.get(label));
    }

    chart = new JFreeChart(plot);
    chart.setTitle(
            new TextTitle(Local_Filter_Manager.getFilterTitle(filter_Id), new Font("Verdana", Font.BOLD, 13)));
    chart.setBorderPaint(null);
    chart.setBackgroundPaint(null);
    chart.getLegend().setFrame(BlockBorder.NONE);
    chart.getLegend().setItemFont(new Font("Verdana", Font.PLAIN, 12));
    String imgUrl = saveToFile(chart, width, height);

    return imgUrl;

}

From source file:jgnash.ui.report.compiled.IncomeExpensePieChart.java

private JFreeChart createPieChart(final Account a) {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    Objects.requireNonNull(a);/*from   w w  w . j  av  a 2s . c  om*/

    PieDataset data = createPieDataSet(a);
    PiePlot plot = new PiePlot(data);

    // rebuilt each time because they're based on the account's commodity
    CurrencyNode defaultCurrency = engine.getDefaultCurrency();
    NumberFormat valueFormat = CommodityFormat.getFullNumberFormat(a.getCurrencyNode());
    NumberFormat percentFormat = new DecimalFormat("0.0#%");
    defaultLabels = new StandardPieSectionLabelGenerator("{0} = {1}", valueFormat, percentFormat);
    percentLabels = new StandardPieSectionLabelGenerator("{0} = {1}\n{2}", valueFormat, percentFormat);

    plot.setLabelGenerator(showPercentCheck.isSelected() ? percentLabels : defaultLabels);

    plot.setLabelGap(.02);
    plot.setInteriorGap(.1);

    // if we had to add a section for the account (because it has it's
    // own transactions, not just child accounts), separate it from children.
    if (data.getIndex(a) != -1) {
        plot.setExplodePercent(a, .10);
    }

    String title;

    // pick an appropriate title
    if (a.getAccountType() == AccountType.EXPENSE) {
        title = rb.getString("Title.PercentExpense");
    } else if (a.getAccountType() == AccountType.INCOME) {
        title = rb.getString("Title.PercentIncome");
    } else {
        title = rb.getString("Title.PercentDist");
    }

    title = title + " - " + a.getPathName();

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

    BigDecimal total = a.getTreeBalance(startField.getLocalDate(), endField.getLocalDate()).abs();

    String subtitle = valueFormat.format(total);
    if (!defaultCurrency.equals(a.getCurrencyNode())) {
        BigDecimal totalDefaultCurrency = total.multiply(a.getCurrencyNode().getExchangeRate(defaultCurrency));
        NumberFormat defaultValueFormat = CommodityFormat.getFullNumberFormat(defaultCurrency);
        subtitle += "  -  " + defaultValueFormat.format(totalDefaultCurrency);
    }
    chart.addSubtitle(new TextTitle(subtitle));
    chart.setBackgroundPaint(null);

    return chart;
}

From source file:jgnash.ui.report.compiled.PayeePieChart.java

private JFreeChart createPieChart(Account a, PieDataset[] data, int index) {
    PiePlot plot = new PiePlot(data[index]);

    // rebuilt each time because they're based on the account's commodity
    NumberFormat valueFormat = CommodityFormat.getFullNumberFormat(a.getCurrencyNode());
    NumberFormat percentFormat = new DecimalFormat("0.0#%");
    defaultLabels = new StandardPieSectionLabelGenerator("{0} = {1}", valueFormat, percentFormat);
    percentLabels = new StandardPieSectionLabelGenerator("{0} = {1}\n{2}", valueFormat, percentFormat);

    plot.setLabelGenerator(showPercentCheck.isSelected() ? percentLabels : defaultLabels);

    plot.setLabelGap(.02);/*from   ww w .  j a  v  a  2  s .  com*/
    plot.setInteriorGap(.1);

    BigDecimal thisTotal = BigDecimal.ZERO;
    for (int i = 0; i < data[index].getItemCount(); i++) {
        thisTotal = thisTotal.add((BigDecimal) (data[index].getValue(i)));
    }
    BigDecimal acTotal = a.getTreeBalance(startField.getLocalDate(), endField.getLocalDate()).abs();

    String title = "";
    String subtitle = "";

    // pick an appropriate title(s)
    if (index == 0) {
        title = a.getPathName();
        subtitle = rb.getString("Column.Credit") + " : " + valueFormat.format(thisTotal);
    } else if (index == 1) {
        title = rb.getString("Column.Balance") + " : " + valueFormat.format(acTotal);
        subtitle = rb.getString("Column.Debit") + " : " + valueFormat.format(thisTotal);
    }

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

    chart.addSubtitle(new TextTitle(subtitle));
    chart.setBackgroundPaint(null);

    return chart;
}

From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java

/**    
* Creates a pie chart with default settings.    
* <P>    /*www .  j  av  a  2s .c o  m*/
* The chart object returned by this method uses a {@link PiePlot} instance     
* as the plot.    
*    
* @param title  the chart title (<code>null</code> permitted).    
* @param dataset  the dataset for the chart (<code>null</code> permitted).    
* @param legend  a flag specifying whether or not a legend is required.    
* @param tooltips  configure chart to generate tool tips?    
* @param locale  the locale (<code>null</code> not permitted).    
*    
* @return A pie chart.    
*     
* @since 1.0.7    
*/
public static JFreeChart createPieChart(String title, PieDataset dataset, boolean legend, boolean tooltips,
        Locale locale) {

    PiePlot plot = new PiePlot(dataset);
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator(locale));
    plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
    if (tooltips) {
        plot.setToolTipGenerator(new StandardPieToolTipGenerator(locale));
    }
    return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

}

From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java

/**    
* Creates a pie chart with default settings.    
* <P>    /*from  ww w . j  a v  a 2  s. c  o m*/
* The chart object returned by this method uses a {@link PiePlot} instance     
* as the plot.    
*    
* @param title  the chart title (<code>null</code> permitted).    
* @param dataset  the dataset for the chart (<code>null</code> permitted).    
* @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, PieDataset dataset, boolean legend, boolean tooltips,
        boolean urls) {

    PiePlot plot = new PiePlot(dataset);
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator());
    plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
    if (tooltips) {
        plot.setToolTipGenerator(new StandardPieToolTipGenerator());
    }
    if (urls) {
        plot.setURLGenerator(new StandardPieURLGenerator());
    }
    return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

}