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

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

Introduction

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

Prototype

public void setLabelShadowPaint(Paint paint) 

Source Link

Document

Sets the section label shadow paint and sends a PlotChangeEvent to all registered listeners.

Usage

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;// www .j  av  a 2 s  .  c  o m
    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;
}