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

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

Introduction

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

Prototype

public void setToolTipGenerator(PieToolTipGenerator generator) 

Source Link

Document

Sets the tool tip generator and sends a PlotChangeEvent to all registered listeners.

Usage

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

/**
 * Creates a pie chart.// w  w w  .java 2s . c  o  m
 *
 * @return A pie chart.
 */
private static JFreeChart createPieChart() {
    JFreeChart chart = ChartFactory.createPieChart(null, null, false, true, false);
    chart.setBackgroundPaint(Color.white);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setInsets(RectangleInsets.ZERO_INSETS);
    plot.setInteriorGap(0.06);
    plot.setStartAngle(0.0);
    plot.setLabelGenerator(null);
    plot.setBaseSectionOutlinePaint(Color.white);
    plot.setBaseSectionOutlineStroke(new BasicStroke(1.2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    plot.setOutlineVisible(false);
    plot.setLabelBackgroundPaint(null);
    plot.setLabelOutlinePaint(null);
    plot.setLabelShadowPaint(null);
    plot.setLabelPadding(RectangleInsets.ZERO_INSETS);
    plot.setLabelFont(new Font("Dialog", Font.PLAIN, 12));
    plot.setLabelPaint(Color.darkGray);
    plot.setToolTipGenerator(new StandardPieToolTipGenerator("{2}"));
    return chart;
}

From source file:KIDLYFactory.java

/**
 * Creates a pie chart with default settings that compares 2 datasets.
 * The colour of each section will be determined by the move from the value
 * for the same key in <code>previousDataset</code>. ie if value1 > value2
 * then the section will be in green (unless <code>greenForIncrease</code>
 * is <code>false</code>, in which case it would be <code>red</code>).
 * Each section can have a shade of red or green as the difference can be
 * tailored between 0% (black) and percentDiffForMaxScale% (bright
 * red/green)./*from   ww w.  j av a 2 s  . co  m*/
 * <p>
 * For instance if <code>percentDiffForMaxScale</code> is 10 (10%), a
 * difference of 5% will have a half shade of red/green, a difference of
 * 10% or more will have a maximum shade/brightness of red/green.
 * <P>
 * The chart object returned by this method uses a {@link PiePlot} instance
 * as the plot.
 * <p>
 * Written by <a href="mailto:opensource@objectlab.co.uk">Benoit
 * Xhenseval</a>.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param previousDataset  the dataset for the last run, this will be used
 *                         to compare each key in the dataset
 * @param percentDiffForMaxScale scale goes from bright red/green to black,
 *                               percentDiffForMaxScale indicate the change
 *                               required to reach top scale.
 * @param greenForIncrease  an increase since previousDataset will be
 *                          displayed in green (decrease red) if true.
 * @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).
 * @param subTitle displays a subtitle with colour scheme if true
 * @param showDifference  create a new dataset that will show the %
 *                        difference between the two datasets.
 *
 * @return A pie chart.
 *
 * @since 1.0.7
 */
public static JFreeChart createPieChart(String title, PieDataset dataset, PieDataset previousDataset,
        int percentDiffForMaxScale, boolean greenForIncrease, boolean legend, boolean tooltips, Locale locale,
        boolean subTitle, boolean showDifference) {

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

    List keys = dataset.getKeys();
    DefaultPieDataset series = null;
    if (showDifference) {
        series = new DefaultPieDataset();
    }

    double colorPerPercent = 255.0 / percentDiffForMaxScale;
    for (Iterator it = keys.iterator(); it.hasNext();) {
        Comparable key = (Comparable) it.next();
        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(title, 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);
    }
    currentTheme.apply(chart);
    return chart;
}

From source file:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java

private static JFreeChart createPieDatasetChart(final PieDatasetChartDefinition chartDefinition) {
    // TODO Make the following accessible from the chartDefinition
    boolean tooltips = true;
    boolean urls = true;
    // -----------------------------------------------------------

    String title = chartDefinition.getTitle();
    boolean legend = chartDefinition.isLegendIncluded();

    PiePlot plot = null;
    plot = chartDefinition.isThreeD() ? new PiePlot3D(chartDefinition) : new PiePlot(chartDefinition);
    JFreeChartEngine.updatePlot(plot, chartDefinition);
    JFreeChart pieChart = new JFreeChart(title, chartDefinition.getTitleFont(), plot, legend);
    TextTitle seriesTitle = new TextTitle("Series Title", new Font("SansSerif", Font.BOLD, 12)); //$NON-NLS-1$ //$NON-NLS-2$
    seriesTitle.setPosition(RectangleEdge.BOTTOM);
    pieChart.setTitle(title);/*w w w .j ava2s.co m*/
    pieChart.setBackgroundPaint(chartDefinition.getChartBackgroundPaint());

    if (tooltips) {
        PieToolTipGenerator tooltipGenerator = new StandardPieToolTipGenerator();
        plot.setToolTipGenerator(tooltipGenerator);
    }

    if (urls) {
        PieURLGenerator urlGenerator = new StandardPieURLGenerator();
        plot.setURLGenerator(urlGenerator);
    }

    return pieChart;
}

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

private void setTooltip(JFreeChart chart) {
    Plot plot = chart.getPlot();//from  ww w . ja  v  a2  s  .  c o  m
    if (plot instanceof PiePlot) {
        PiePlot pp = (PiePlot) plot;

        pp.setToolTipGenerator(new PieToolTipGeneratorImpl(labelFormat));

    } else if (plot instanceof CategoryPlot) {
        CategoryPlot cp = (CategoryPlot) plot;
        CategoryItemRenderer renderer = cp.getRenderer();
        renderer.setBaseToolTipGenerator(new CategoryToolTipGeneratorImpl(labelFormat));
    }
    /*else if(plot instanceof XYPlot) {
       XYPlot cp=(XYPlot) plot;
       XYItemRenderer renderer = cp.getRenderer();
       renderer.setBaseToolTipGenerator(new XYToolTipGeneratorImpl(labelFormat));
    }*/

}

From source file:org.operamasks.faces.render.graph.PieChartRenderer.java

protected JFreeChart createChart(UIChart comp) {
    Dataset dataset = createDataset(comp);
    JFreeChart chart = null;/*  w  w  w . j a va  2  s  .co m*/
    PiePlot pieplot = null;

    boolean ring = Coercion.coerceToBoolean(comp.getAttributes().get("ring"));

    if (dataset instanceof CategoryDataset) {
        CategoryDataset catset = (CategoryDataset) dataset;

        if (catset.getRowCount() == 1) {
            PieDataset pieset = new CategoryToPieDataset(catset, TableOrder.BY_ROW, 0);

            if (ring) {
                chart = ChartFactory.createRingChart(null, pieset, false, false, false);
            } else if (comp.isEffect3D()) {
                chart = ChartFactory.createPieChart3D(null, pieset, false, false, false);
            } else {
                chart = ChartFactory.createPieChart(null, pieset, false, false, false);
            }

            pieplot = (PiePlot) chart.getPlot();
        } else {
            if (comp.isEffect3D()) {
                chart = ChartFactory.createMultiplePieChart3D(null, catset, TableOrder.BY_ROW, false, false,
                        false);
            } else {
                chart = ChartFactory.createMultiplePieChart(null, catset, TableOrder.BY_ROW, false, false,
                        false);
            }

            pieplot = (PiePlot) ((MultiplePiePlot) chart.getPlot()).getPieChart().getPlot();
        }
    }

    if (pieplot != null) {
        if (!comp.isDrawItemLabel()) {
            pieplot.setLabelGenerator(null);
        }

        if (comp.isShowItemTips()) {
            pieplot.setToolTipGenerator(new StandardPieToolTipGenerator());
        }

        Object startAngle = comp.getAttributes().get("startAngle");
        if (startAngle != null) {
            pieplot.setStartAngle(Coercion.coerceToDouble(startAngle));
        }
    }

    return chart;
}

From source file:fr.inria.soctrace.framesoc.ui.piechart.view.StatisticsPieChartView.java

/**
 * Creates the chart.//from  w w  w .  j a  v a 2  s .  co m
 * 
 * @param dataset
 *            the dataset.
 * @param loader
 *            the pie chart loader
 * @param dataRequested
 *            flag indicating if the data have been requested for the current loader and the
 *            current interval
 * @return the pie chart
 */
private JFreeChart createChart(PieDataset dataset, String title, IPieChartLoader loader,
        boolean dataRequested) {

    JFreeChart chart = ChartFactory.createPieChart(title, dataset, HAS_LEGEND, HAS_TOOLTIPS, HAS_URLS);

    // legend
    if (HAS_LEGEND) {
        LegendTitle legend = chart.getLegend();
        legend.setPosition(RectangleEdge.LEFT);
    }

    // plot
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setSectionOutlinesVisible(false);
    plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    plot.setNoDataMessage(
            "No data available " + (dataRequested ? "in this time interval" : "yet. Press the Load button."));
    plot.setCircular(true);
    plot.setLabelGenerator(null); // hide labels
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlineVisible(false);
    plot.setShadowPaint(Color.WHITE);
    plot.setBaseSectionPaint(Color.WHITE);
    StandardPieToolTipGenerator g = (StandardPieToolTipGenerator) plot.getToolTipGenerator();
    NumberFormat format = ValueLabelProvider.getActualFormat(loader.getFormat(), getTimeUnit());
    StandardPieToolTipGenerator sg = new StandardPieToolTipGenerator(g.getLabelFormat(), format,
            g.getPercentFormat());
    plot.setToolTipGenerator(sg);

    for (Object o : dataset.getKeys()) {
        String key = (String) o;
        plot.setSectionPaint(key, loader.getColor(key).getAwtColor());
    }
    return chart;
}

From source file:edu.jhuapl.graphs.jfreechart.JFreeChartPieGraphSource.java

@SuppressWarnings("unchecked")
@Override/* w  w  w.  j  av  a 2s. c om*/
public void initialize() throws GraphException {
    String title = getParam(GraphSource.GRAPH_TITLE, String.class, DEFAULT_TITLE);
    boolean legend = getParam(GraphSource.GRAPH_LEGEND, Boolean.class, DEFAULT_GRAPH_LEGEND);
    boolean graphToolTip = getParam(GraphSource.GRAPH_TOOL_TIP, Boolean.class, DEFAULT_GRAPH_TOOL_TIP);
    boolean graphDisplayLabel = getParam(GraphSource.GRAPH_DISPLAY_LABEL, Boolean.class, false);
    boolean legendBorder = getParam(GraphSource.LEGEND_BORDER, Boolean.class, DEFAULT_LEGEND_BORDER);
    boolean graphBorder = getParam(GraphSource.GRAPH_BORDER, Boolean.class, DEFAULT_GRAPH_BORDER);
    Font titleFont = getParam(GraphSource.GRAPH_FONT, Font.class, DEFAULT_GRAPH_TITLE_FONT);
    String noDataMessage = getParam(GraphSource.GRAPH_NO_DATA_MESSAGE, String.class,
            DEFAULT_GRAPH_NO_DATA_MESSAGE);
    PieGraphData pieGraphData = makeDataSet();
    Map<Comparable, Paint> colors = pieGraphData.colors;

    this.chart = ChartFactory.createPieChart(title, pieGraphData.data, false, graphToolTip, false);

    Paint backgroundColor = getParam(GraphSource.BACKGROUND_COLOR, Paint.class, DEFAULT_BACKGROUND_COLOR);
    Paint plotColor = getParam(JFreeChartTimeSeriesGraphSource.PLOT_COLOR, Paint.class, backgroundColor);
    Paint labelColor = getParam(JFreeChartTimeSeriesGraphSource.GRAPH_LABEL_BACKGROUND_COLOR, Paint.class,
            DEFAULT_BACKGROUND_COLOR);

    this.chart.setBackgroundPaint(backgroundColor);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(plotColor);
    plot.setNoDataMessage(noDataMessage);

    if (!graphDisplayLabel) {
        plot.setLabelGenerator(null);
    } else {
        plot.setInteriorGap(0.001);
        plot.setMaximumLabelWidth(.3);
        //           plot.setIgnoreNullValues(true);
        plot.setIgnoreZeroValues(true);
        plot.setShadowPaint(null);
        //           plot.setOutlineVisible(false);
        //TODO use title font?
        Font font = plot.getLabelFont();
        plot.setLabelLinkStyle(PieLabelLinkStyle.CUBIC_CURVE);
        plot.setLabelFont(font.deriveFont(font.getSize2D() * .75f));
        plot.setLabelBackgroundPaint(labelColor);
        plot.setLabelShadowPaint(null);
        plot.setLabelOutlinePaint(null);
        plot.setLabelGap(0.001);
        plot.setLabelLinkMargin(0.0);
        plot.setLabelLinksVisible(true);
        //           plot.setSimpleLabels(true);
        //           plot.setCircular(true);
    }

    if (!graphBorder) {
        plot.setOutlineVisible(false);
    }

    if (title != null && !"".equals(title)) {
        TextTitle title1 = new TextTitle();
        title1.setText(title);
        title1.setFont(titleFont);
        title1.setPadding(3, 2, 5, 2);
        chart.setTitle(title1);
    } else {
        chart.setTitle((TextTitle) null);
    }
    plot.setLabelPadding(new RectangleInsets(1, 1, 1, 1));
    //Makes a wrapper for the legend to remove the border around it
    if (legend) {
        LegendTitle legend1 = new LegendTitle(chart.getPlot());
        BlockContainer wrapper = new BlockContainer(new BorderArrangement());

        if (legendBorder) {
            wrapper.setFrame(new BlockBorder(1, 1, 1, 1));
        } else {
            wrapper.setFrame(new BlockBorder(0, 0, 0, 0));
        }

        BlockContainer items = legend1.getItemContainer();
        items.setPadding(2, 10, 5, 2);
        wrapper.add(items);
        legend1.setWrapper(wrapper);
        legend1.setPosition(RectangleEdge.BOTTOM);
        legend1.setHorizontalAlignment(HorizontalAlignment.CENTER);

        if (params.get(GraphSource.LEGEND_FONT) instanceof Font) {
            legend1.setItemFont(((Font) params.get(GraphSource.LEGEND_FONT)));
        }

        chart.addSubtitle(legend1);
        plot.setLegendLabelGenerator(new PieGraphLabelGenerator());
    }

    for (Comparable category : colors.keySet()) {
        plot.setSectionPaint(category, colors.get(category));
    }

    plot.setToolTipGenerator(new PieGraphToolTipGenerator(pieGraphData));
    plot.setURLGenerator(new PieGraphURLGenerator(pieGraphData));

    initialized = true;
}

From source file:com.appnativa.rare.ui.chart.jfreechart.ChartHandler.java

private void customizePiePlot(ChartDefinition cd, PiePlot plot, PieCollection pie) {
    PlotInformation pi = cd.getPlotInformation();

    plot.setBackgroundPaint(null);//w  w w  . jav  a 2s.  c o  m
    plot.setOutlineVisible(false);
    customizeBasicPlot(plot, pi);

    List<RenderableDataItem> rows = cd.getSeries();
    int len = (rows == null) ? 0 : rows.size();
    ChartDataItem di;
    iComponentPainter bp;
    Paint p = null;

    if (len > 0) {
        rows = rows.get(0).getItems();
        len = rows.size();
    }

    for (int i = 0; i < len; i++) {
        di = (ChartDataItem) rows.get(i);
        bp = di.getComponentPainter();

        iPlatformPaint pp;

        if (bp == null) {
            p = di.getBackground();
        } else if (bp.getBackgroundPainter() != null) {
            pp = bp.getBackgroundPainter().getPaint(100, 100);
            p = (pp == null) ? null : pp.getPaint();
        }

        if (p == null) {
            p = getDefaultColor(i);
        }

        plot.setSectionPaint(di.getDomainValue().toString(), p);
    }

    if (pie.getExplodedPiece() != null) {
        plot.setExplodePercent(pie.getExplodedPiece(), 0.50);
    }

    plot.setLabelBackgroundPaint(null);
    plot.setLabelOutlinePaint(null);
    plot.setLabelShadowPaint(null);

    UIColor fg = cd.getTextColor(plotLabelColor);
    UIFont font = cd.getTextFont(plotLabelFont);

    plot.setLabelFont(font);
    plot.setLabelPaint(fg);

    if (cd.isShowPlotLabels()) {
        String format = (pi == null) ? null : pi.getLabelsFormat();

        plot.setLabelGenerator(new PieLabelGenerator(cd, format));
    }

    if (cd.isShowToolTips()) {
        plot.setToolTipGenerator(new PieToolTipLabelGenerator(cd, false));
    }
}

From source file:com.naryx.tagfusion.cfm.tag.awt.cfCHART.java

private JFreeChart renderPieChart(cfSession _Session, cfCHARTInternalData chartData,
        List<cfCHARTSERIESData> series, String tipStyle, String drillDownUrl) throws cfmRunTimeException {
    // Retrieve the attributes of the chart
    String backgroundColorStr = getDynamic(_Session, "BACKGROUNDCOLOR").toString();
    Color backgroundColor = convertStringToColor(backgroundColorStr);

    String foregroundColorStr = getDynamic(_Session, "FOREGROUNDCOLOR").toString();
    Color foregroundColor = convertStringToColor(foregroundColorStr);

    String labelFormat = getDynamic(_Session, "LABELFORMAT").toString().toLowerCase();
    if (!labelFormat.equals("number") && !labelFormat.equals("currency") && !labelFormat.equals("percent"))
        throw newRunTimeException(
                "The labelFormat value '" + labelFormat + "' is not supported with pie charts");

    String pieSliceStyle = getDynamic(_Session, "PIESLICESTYLE").toString().toLowerCase();

    String title = null;/*from  w ww .  j av  a 2s .  com*/
    if (containsAttribute("TITLE"))
        title = getDynamic(_Session, "TITLE").toString();

    Font font = getFont(_Session);

    cfCHARTSERIESData seriesData = series.get(0);

    boolean bShow3D = getDynamic(_Session, "SHOW3D").getBoolean();
    if (bShow3D && !seriesData.getType().equals("pie"))
        throw newRunTimeException("Only bar, line, horizontal bar and pie charts can be displayed in 3D");

    boolean bShowBorder = getDynamic(_Session, "SHOWBORDER").getBoolean();

    boolean bShowLegend = true; // default to true for pie charts
    if (containsAttribute("SHOWLEGEND"))
        bShowLegend = getDynamic(_Session, "SHOWLEGEND").getBoolean();

    // Get the plot for the chart and configure it
    PiePlot plot = getPiePlot(series, pieSliceStyle, bShow3D);
    setBackgroundImage(_Session, plot, chartData.getImageData());
    plot.setBackgroundPaint(backgroundColor);
    plot.setLabelBackgroundPaint(backgroundColor);
    plot.setLabelShadowPaint(backgroundColor);

    // Set the labels color
    plot.setLabelPaint(convertStringToColor(seriesData.getDataLabelColor()));

    // Set the labels font
    plot.setLabelFont(getFont(seriesData.getDataLabelFont(), seriesData.getDataLabelFontBold(),
            seriesData.getDataLabelFontItalic(), seriesData.getDataLabelFontSize()));

    String dataLabelStyle = seriesData.getDataLabelStyle();

    NumberFormat percentInstance = NumberFormat.getPercentInstance();
    percentInstance.setMaximumFractionDigits(3);

    NumberFormat numberFormat = null;
    if (labelFormat.equals("number")) {
        // Only display the value in the Label as a number
        numberFormat = NumberFormat.getInstance();
        if (dataLabelStyle.equals("none"))
            plot.setLabelGenerator(null);
        else if (dataLabelStyle.equals("value"))
            plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator("{1}"));
        else if (dataLabelStyle.equals("rowlabel"))
            plot.setLabelGenerator(
                    new org.jfree.chart.labels.StandardPieSectionLabelGenerator(seriesData.getSeriesLabel()));
        else if (dataLabelStyle.equals("columnlabel"))
            plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator("{0}"));
        else if (dataLabelStyle.equals("pattern"))
            plot.setLabelGenerator(
                    new org.jfree.chart.labels.StandardPieSectionLabelGenerator("{0} {1} ({2} of {3})"));
        else {
            String pattern = java.text.MessageFormat.format(dataLabelStyle,
                    new Object[] { seriesData.getSeriesLabel(), "{0}", "{1}", "{2}", "{3}" });
            plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator(pattern));
        }
    } else if (labelFormat.equals("currency")) {
        // Only display the value in the Label as a currency
        numberFormat = NumberFormat.getCurrencyInstance();
        if (dataLabelStyle.equals("none"))
            plot.setLabelGenerator(null);
        else if (dataLabelStyle.equals("value"))
            plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator("{1}",
                    NumberFormat.getCurrencyInstance(), percentInstance));
        else if (dataLabelStyle.equals("rowlabel"))
            plot.setLabelGenerator(
                    new org.jfree.chart.labels.StandardPieSectionLabelGenerator(seriesData.getSeriesLabel()));
        else if (dataLabelStyle.equals("columnlabel"))
            plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator("{0}"));
        else if (dataLabelStyle.equals("pattern"))
            plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator(
                    "{0} {1} ({2} of {3})", NumberFormat.getCurrencyInstance(), percentInstance));
        else {
            String pattern = java.text.MessageFormat.format(dataLabelStyle,
                    new Object[] { seriesData.getSeriesLabel(), "{0}", "{1}", "{2}", "{3}" });
            plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator(pattern,
                    NumberFormat.getCurrencyInstance(), percentInstance));
        }
    } else if (labelFormat.equals("percent")) {
        // Only display the value in the Label as a percent
        numberFormat = percentInstance;
        if (dataLabelStyle.equals("none"))
            plot.setLabelGenerator(null);
        else if (dataLabelStyle.equals("value"))
            plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator("{1}",
                    percentInstance, percentInstance));
        else if (dataLabelStyle.equals("rowlabel"))
            plot.setLabelGenerator(
                    new org.jfree.chart.labels.StandardPieSectionLabelGenerator(seriesData.getSeriesLabel()));
        else if (dataLabelStyle.equals("columnlabel"))
            plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator("{0}"));
        else if (dataLabelStyle.equals("pattern"))
            plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator(
                    "{0} {1} ({2} of {3})", percentInstance, percentInstance));
        else {
            String pattern = java.text.MessageFormat.format(dataLabelStyle,
                    new Object[] { seriesData.getSeriesLabel(), "{0}", "{1}", "{2}", "{3}" });
            plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator(pattern,
                    percentInstance, percentInstance));
        }
    }

    if (!tipStyle.equals("none")) {
        plot.setToolTipGenerator(new StandardPieToolTipGenerator(
                StandardPieToolTipGenerator.DEFAULT_SECTION_LABEL_FORMAT, numberFormat, numberFormat));
    }

    if (drillDownUrl != null) {
        plot.setURLGenerator(new com.newatlanta.bluedragon.PieURLGenerator(drillDownUrl, numberFormat));
    }

    // Get the chart and configure it
    JFreeChart chart = new JFreeChart(null, null, plot, false);
    chart.setBorderVisible(bShowBorder);
    chart.setBackgroundPaint(backgroundColor);
    setTitle(chart, title, font, foregroundColor, chartData.getTitles());
    setLegend(chart, bShowLegend, font, foregroundColor, backgroundColor, chartData.getLegendData());

    return chart;
}

From source file:org.jfree.chart.ChartFactory.java

/**
 * Creates a pie chart with default settings.
 * <P>/*from   w ww .j  av  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} permitted).
 * @param dataset  the dataset for the chart ({@code null} permitted).
 * @param locale  the locale ({@code null} not permitted).
 *
 * @return A pie chart.
 *
 * @since 1.0.7
 */
public static JFreeChart createPieChart(String title, PieDataset dataset, Locale locale) {

    PiePlot plot = new PiePlot(dataset);
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator(locale));
    plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
    plot.setToolTipGenerator(new StandardPieToolTipGenerator(locale));
    JFreeChart chart = new JFreeChart(title, plot);
    currentTheme.apply(chart);
    return chart;

}