List of usage examples for org.jfree.data.event SelectionChangeListener SelectionChangeListener
SelectionChangeListener
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 www. ja va 2 s . 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; }