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

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

Introduction

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

Prototype

public void setLabelGenerator(PieSectionLabelGenerator generator) 

Source Link

Document

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

Usage

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

private static JFreeChart createChart(PieDataset piedataset) {
    JFreeChart jfreechart = ChartFactory.createPieChart("Pie Chart Demo 8", piedataset, false, true, false);
    PiePlot pieplot = (PiePlot) jfreechart.getPlot();
    pieplot.setLabelGenerator(new CustomLabelGenerator());
    return jfreechart;
}

From source file:com.globalsight.util.JfreeCharUtil.java

public static void drawPieChart2D(String title, Map<String, Double> datas, File OutFile) {
    PieDataset dataset = buildDatas(datas);
    JFreeChart chart = ChartFactory.createPieChart(title, dataset, true, true, false);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})",
            NumberFormat.getNumberInstance(), new DecimalFormat("0.00%")));
    plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})"));
    chart.setBackgroundPaint(Color.white);
    plot.setCircular(true);//from w ww .j av a 2  s . c  o m
    TextTitle textTitle = new TextTitle(title);
    Font font = new Font(textTitle.getFont().getName(), Font.CENTER_BASELINE, 20);
    textTitle.setFont(font);
    chart.setTitle(textTitle);
    FileOutputStream fos_jpg = null;

    try {
        fos_jpg = new FileOutputStream(OutFile);
        ChartUtilities.writeChartAsJPEG(fos_jpg, 1, chart, 640, 480, null);
        fos_jpg.close();
    } catch (Exception e) {
        s_logger.error(e.getMessage(), e);
    }
}

From source file:fr.paris.lutece.plugins.form.business.GraphTypePieChart.java

/**
* return the PieChartGraph  JFreeChart graph
* @param listStatistic listStatistic// w w  w . ja  v  a2s  . c  o m
* @param strGraphTitle graph title
* @param nGraphThreeDimension true if the graph must be in three dimension
* @param nGraphLabelValue true if the labels must appear in the graph
* @return the JFreeChart graph associate to the graph type
*/
public static JFreeChart createPieChartGraph(List<StatisticEntrySubmit> listStatistic, String strGraphTitle,
        boolean nGraphThreeDimension, boolean nGraphLabelValue) {
    PieDataset pieDataset = createPieDataset(listStatistic);
    JFreeChart chart;

    if (nGraphThreeDimension) {
        chart = ChartFactory.createPieChart3D(strGraphTitle, pieDataset, true, true, false);
    } else {
        chart = ChartFactory.createPieChart(strGraphTitle, pieDataset, true, true, false);
    }

    PiePlot plot = (PiePlot) chart.getPlot();

    if (nGraphLabelValue) {
        plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{2}"));
    } else {
        plot.setLabelGenerator(null);
    }

    return chart;
}

From source file:nl.wur.plantbreeding.www.marker2seq.GoDistribution.java

/**
 * Generate the Pie chart for a set of given Go terms.
 * @param distrib a HashMap of GO name and GO frequency
 * @param title the title of the GO graph
 * @param url the url used for the tooltips
 * @param session the HttpSession used to save the file
 * @param legend Print the legend or not
 * @param tooltips Add tooltip or not/* www  .ja va  2  s  .  c o  m*/
 * @param urls Add urls or not (link in the graph)
 * @param max Maximum number of item to display
 * @return a list containing the filename and the map for the figure
 * @throws IOException when something happens while writting the image
 */
public static String[] generateDistribution(final HashMap<String, Integer> distrib, final String title,
        final String url, final HttpSession session, final boolean legend, final boolean tooltips,
        final boolean urls, final int max) throws IOException {

    final PieChart piec = new PieChart();
    final PieDataset piedata = piec.createDataset(distrib);

    final JFreeChart chart = piec.createChart(piedata, title, legend, tooltips, urls);
    final PiePlot plot = (PiePlot) chart.getPlot();
    if (distrib.size() >= max) {
        plot.setLabelGenerator(null);
    }
    plot.setURLGenerator(new StandardPieURLGenerator(url, "section"));

    final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());

    final String filename = ServletUtilities.saveChartAsPNG(chart, 500, 400, info, session);

    final String map = ChartUtilities.getImageMap(filename, info);

    final String[] output = { filename, map };
    return output;
}

From source file:nl.wur.plantbreeding.www.marker2seq.GoDistribution.java

/**
 * Generate the Pie chart for a set of given Go terms.
 * @param gotermlist of String (here GO names)
 * @param title the title of the GO graph
 * @param url the url used for the tooltips
 * @param session the HttpSession used to save the file
 * @param legend Print the legend or not
 * @param tooltips Add tooltip or not//www.  j  a v  a 2  s.  c  o  m
 * @param urls Add urls or not (link in the graph)
 * @param max Maximum number of item to display
 * @return a list containing the filename and the map for the figure
 * @throws IOException when something happens while writting the image
 */
public static String[] generateDistribution(final List<String> gotermlist, final String title, final String url,
        final HttpSession session, final boolean legend, final boolean tooltips, final boolean urls,
        final int max) throws IOException {
    final PieChart piec = new PieChart();
    final PieDataset dataset = piec.createDataset(gotermlist);
    final JFreeChart chart = piec.createChart(dataset, title, legend, tooltips, urls);
    final PiePlot plot = (PiePlot) chart.getPlot();
    if (gotermlist.size() >= max) {
        plot.setLabelGenerator(null);
    }
    plot.setURLGenerator(new StandardPieURLGenerator(url, "section"));

    final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());

    final String filename = ServletUtilities.saveChartAsPNG(chart, 500, 400, info, session);

    final String map = ChartUtilities.getImageMap(filename, info);

    final String[] output = { filename, map };
    return output;

}

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

private static JFreeChart createPieChart(PieDataset dataset) {

    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());
    }/*  ww  w .j av a2s  . c  o m*/
    if (urls) {
        plot.setURLGenerator(new StandardPieURLGenerator());
    }
    JFreeChart chart = new JFreeChart("Pie Chart Demo 1", JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    plot.setSectionOutlinesVisible(false);
    plot.setNoDataMessage("No data available");

    return chart;

}

From source file:com.haskins.cloudtrailviewer.utils.ChartFactory.java

private static ChartPanel createPieChart(String type, List<Entry<String, Integer>> events, int width,
        int height) {

    DefaultPieDataset dataset = new DefaultPieDataset();

    for (Map.Entry<String, Integer> event : events) {
        dataset.setValue(event.getKey(), event.getValue());
    }//from  w  w w.java 2 s. c  o m

    JFreeChart jFChart;
    if (type.contains("3d")) {
        jFChart = org.jfree.chart.ChartFactory.createPieChart3D("", dataset, false, true, false);
    } else {
        jFChart = org.jfree.chart.ChartFactory.createPieChart("", dataset, false, true, false);
    }

    PiePlot plot = (PiePlot) jFChart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setInteriorGap(0.01);
    plot.setOutlineVisible(false);
    plot.setLabelGenerator(null);

    // use gradients and white borders for the section colours
    plot.setBaseSectionOutlinePaint(Color.WHITE);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f));

    TextTitle t = jFChart.getTitle();
    t.setHorizontalAlignment(HorizontalAlignment.LEFT);
    t.setFont(new Font("Arial", Font.BOLD, 16));

    final ChartPanel jChartPanel = new ChartPanel(jFChart, width, height, width, height, width, height, false,
            false, true, true, false, true);
    jChartPanel.setMinimumDrawWidth(0);
    jChartPanel.setMaximumDrawWidth(Integer.MAX_VALUE);
    jChartPanel.setMinimumDrawHeight(0);
    jChartPanel.setMaximumDrawHeight(Integer.MAX_VALUE);

    return jChartPanel;
}

From source file:org.gaixie.micrite.jfreechart.style.PieStyle.java

/**
 * ?1 ,? Familiar(30%) //from ww  w.j a va2  s .  c  om
 * @param chart
 */
public static void styleOne(JFreeChart chart) {
    PiePlot plot = (PiePlot) chart.getPlot();
    PieDataset pd = plot.getDataset();
    PieStyle.setBackground(chart);
    if (pd != null) {
        //?
        plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2})"));
        //??
        for (int i = 0; i < pd.getItemCount(); i++) {
            int color = i % colors.length;
            plot.setSectionPaint(pd.getKey(i), colors[color]);
        }
    } else {
        plot.setNoDataMessage("NO DATA");
    }

}

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 w  w  . j ava2s.com*/
    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:com.mxgraph.examples.swing.chart.PieChartDemo1.java

/**
 * Creates a chart./*from  w w  w  .  j  a  v a  2  s.c o  m*/
 *
 * @param dataset  the dataset.
 *
 * @return A chart.
 */
public static JFreeChart createChart(PieDataset dataset) {

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

    PiePlot plot = (PiePlot) chart.getPlot();

    plot.setSectionOutlinesVisible(false);
    plot.setNoDataMessage("No data available");

    plot.setCircular(true);
    plot.setLabelGap(0.01D);//
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}:\r\n{1}({2})",
            NumberFormat.getNumberInstance(), new DecimalFormat("0.00%"))); //  //
    plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})"));

    chart.getTitle().setFont(new Font("", Font.PLAIN, 20));//
    PiePlot piePlot = (PiePlot) chart.getPlot();//
    piePlot.setLabelFont(new Font("", Font.PLAIN, 10));
    chart.getLegend().setItemFont(new Font("", Font.PLAIN, 10));

    return chart;

}