Example usage for org.jfree.chart.entity PieSectionEntity getDataset

List of usage examples for org.jfree.chart.entity PieSectionEntity getDataset

Introduction

In this page you can find the example usage for org.jfree.chart.entity PieSectionEntity getDataset.

Prototype

public PieDataset getDataset() 

Source Link

Document

Returns the dataset this entity refers to.

Usage

From source file:org.openfaces.component.chart.impl.helpers.ChartInfoUtil.java

public static PieSectorInfo getPieSectorInfo(ChartEntity entity) {
    if (entity instanceof PieSectionEntity) {
        PieSectionEntity pieEntity = (PieSectionEntity) entity;
        return getPieSectorInfo(pieEntity.getDataset(), pieEntity.getSectionKey(), pieEntity.getPieIndex());
    }/*from  w  w w  . j  ava  2 s .c o m*/

    return null;
}

From source file:com.igalia.java.zk.components.JFreeChartEngine.java

/**
 * decode PieSectionEntity into key-value pair of Area's componentScope.
 *//*from   w  w  w .  j  a va 2 s.co m*/
private void decodePieSectionInfo(Area area, PieSectionEntity info) {
    PieDataset dataset = info.getDataset();
    Comparable category = info.getSectionKey();
    area.setAttribute("value", dataset.getValue(category));
    area.setAttribute("category", category);
}

From source file:dbseer.gui.panel.DBSeerSelectableChartPanel.java

@Override
public void chartMouseClicked(ChartMouseEvent chartMouseEvent) {
    ChartEntity entity = chartMouseEvent.getEntity();
    MouseEvent mouseEvent = chartMouseEvent.getTrigger();

    if (SwingUtilities.isLeftMouseButton(mouseEvent) && entity != null && entity instanceof PieSectionEntity) {
        java.util.List<String> names = dataset.getTransactionTypeNames();
        PieSectionEntity pieSectionEntity = (PieSectionEntity) entity;
        int idx = pieSectionEntity.getSectionIndex();

        String name = (String) JOptionPane.showInputDialog(null, "Enter the name for this transaction type",
                "Transaction Type", JOptionPane.PLAIN_MESSAGE, null, null, "");

        if (name != null) {
            if (names.contains(name) && !names.get(idx).equals(name) && !name.isEmpty()) {
                JOptionPane.showMessageDialog(null,
                        "Please enter a different name for the transaction type.\nEach name has to be unique.",
                        "Warning", JOptionPane.WARNING_MESSAGE);
            } else {
                PieDataset oldDataset = pieSectionEntity.getDataset();
                DefaultPieDataset newDataset = new DefaultPieDataset();

                PiePlot plot = (PiePlot) chart.getPlot();
                String oldName = (String) oldDataset.getKey(idx);
                names.set(idx, name);//from www .  j  av a  2 s .  com
                dataset.setTransactionTypeName(idx, name);

                for (int i = 0; i < oldDataset.getItemCount(); ++i) {
                    String key = (String) oldDataset.getKey(i);
                    Number number = oldDataset.getValue(i);

                    if (key.equals(oldName)) {
                        if (name.isEmpty())
                            newDataset.setValue("Transaction Type " + (i + 1), number);
                        else
                            newDataset.setValue(name, number);
                    } else {
                        newDataset.setValue(key, number);
                    }
                }

                Paint[] tempPaint = new Paint[oldDataset.getItemCount()];
                for (int i = 0; i < oldDataset.getItemCount(); ++i) {
                    String key = (String) oldDataset.getKey(i);
                    tempPaint[i] = plot.getSectionPaint(key);
                }

                ((DefaultPieDataset) oldDataset).clear();
                plot.setDataset(newDataset);

                for (int i = 0; i < newDataset.getItemCount(); ++i) {
                    String key = (String) newDataset.getKey(i);
                    plot.setSectionPaint(key, tempPaint[i]);
                }
            }
        }
    }
}