Example usage for org.jfree.chart.labels StandardPieToolTipGenerator StandardPieToolTipGenerator

List of usage examples for org.jfree.chart.labels StandardPieToolTipGenerator StandardPieToolTipGenerator

Introduction

In this page you can find the example usage for org.jfree.chart.labels StandardPieToolTipGenerator StandardPieToolTipGenerator.

Prototype

public StandardPieToolTipGenerator(String labelFormat, NumberFormat numberFormat, NumberFormat percentFormat) 

Source Link

Document

Creates an item label generator using the specified number formatters.

Usage

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

/**
 * Creates the chart./*from  w w w  .j a  va  2s .c  o  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: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 a  v  a2s  . c  om
    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;
}