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

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

Introduction

In this page you can find the example usage for org.jfree.data.extension.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.chart.demo.selection.SelectionDemo6Pie.java

private static JFreeChart createChart(final PieDataset dataset,
        DatasetSelectionExtension<PieCursor<String>> ext) {
    JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 2", dataset);

    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);//from  w w  w. j  ava 2 s .c o  m
    plot.setInteriorGap(0.1);

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

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

    return chart;
}