Example usage for org.jfree.data.datasetextension.impl PieCursor PieCursor

List of usage examples for org.jfree.data.datasetextension.impl PieCursor PieCursor

Introduction

In this page you can find the example usage for org.jfree.data.datasetextension.impl PieCursor PieCursor.

Prototype

public PieCursor() 

Source Link

Document

creates a cursor without assigned position (the cursor will only be valid if setPosition is called at some time)

Usage

From source file:org.jfree.expdemo.SelectionDemo6Pie.java

private static JFreeChart createChart(final PieDataset dataset, DatasetSelectionExtension ext) {
    JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 2", // chart title
            dataset, // dataset
            true, // include legend
            true, false);/*from   w  ww.  j  a v  a  2s  . c  o m*/

    final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setSectionPaint("One", new Color(160, 160, 255));
    plot.setSectionPaint("Two", new Color(128, 128, 255 - 32));
    plot.setSectionPaint("Three", new Color(96, 96, 255 - 64));
    plot.setSectionPaint("Four", new Color(64, 64, 255 - 96));
    plot.setSectionPaint("Five", new Color(32, 32, 255 - 128));
    plot.setSectionPaint("Six", new Color(0, 0, 255 - 144));

    plot.setNoDataMessage("No data available");

    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2} percent)"));
    plot.setLabelBackgroundPaint(new Color(220, 220, 220));

    plot.setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator("Tooltip for legend item {0}"));
    plot.setSimpleLabels(true);
    plot.setInteriorGap(0.1);

    //pie plots done use abstract renderers need to react to selection on our own
    final PieCursor cursor = new PieCursor();

    ext.addSelectionChangeListener(new SelectionChangeListener() {
        public void selectionChanged(SelectionChangeEvent event) {
            for (int i = 0; i < dataset.getItemCount(); i++) {
                cursor.setPosition(dataset.getKey(i));
                if (event.getSelectionExtension().isSelected(cursor)) {
                    plot.setExplodePercent(cursor.key, 0.15);
                } else {
                    plot.setExplodePercent(cursor.key, 0.0);
                }
            }
        }
    });

    return chart;
}