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

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

Introduction

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

Prototype

public Paint getSectionPaint(int section) 

Source Link

Document

Returns the paint for the specified section.

Usage

From source file:lu.lippmann.cdb.common.gui.DragAndDroppablePieChartPanel.java

/**
 * {@inheritDoc}//from   ww w .  j a  v  a2s  .com
 */
@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2d = (Graphics2D) g;
    if (!released && source != null) {
        final PiePlot plot = ((PiePlot) getChart().getPlot());
        final Comparable<?> key = plot.getDataset().getKey(source.getSectionIndex());
        final Color color = (Color) plot.getSectionPaint(key);
        g2d.translate(tx, ty);
        g2d.setColor(color);
        g2d.fill(source.getArea());
    }
}

From source file:edu.uara.wrappers.customcharts.CustomPieChart.java

/**
 * get series color (section paint)/*from   ww  w.j  a  v a2s . c o  m*/
 * @param series
 * @return
 */
@Override
public Color getSeriesColor(int series) {
    Color color = null;
    Plot plot = chart.getPlot();
    if (plot instanceof PiePlot) {
        PiePlot p = (PiePlot) chart.getPlot();
        PieDataset pds = p.getDataset();
        String section = pds.getKey(series).toString();
        color = (Color) p.getSectionPaint(section);
    } else if (plot instanceof MultiplePiePlot) {
        MultiplePiePlot p = (MultiplePiePlot) plot;
        JFreeChart pieCh = p.getPieChart();
        PiePlot piePlot = (PiePlot) pieCh.getPlot();
        PieDataset pds = piePlot.getDataset();
        String section = pds.getKey(series).toString();
        color = (Color) piePlot.getSectionPaint(section);
    }
    return color;
}

From source file:net.sf.dynamicreports.test.jasper.chart.ChartSeriesColorsByNameTest.java

@Override
public void test() {
    super.test();

    numberOfPagesTest(1);/*from   w w w . j  a va2s  .c  o  m*/

    chartCountTest("summary.chart1", 1);
    JFreeChart chart = getChart("summary.chart1", 0);
    CategoryItemRenderer renderer1 = chart.getCategoryPlot().getRenderer();
    CategoryDataset dataset1 = chart.getCategoryPlot().getDataset();
    for (int i = 0; i < dataset1.getRowCount(); i++) {
        String key = (String) dataset1.getRowKey(i);
        Assert.assertNotNull("null series color", colors.get(key));
        Assert.assertEquals("series color", colors.get(key), renderer1.getSeriesPaint(i));
    }

    chartCountTest("summary.chart2", 1);
    chart = getChart("summary.chart2", 0);
    CategoryItemRenderer renderer2 = chart.getCategoryPlot().getRenderer();
    CategoryDataset dataset2 = chart.getCategoryPlot().getDataset();
    for (int i = 0; i < dataset2.getRowCount(); i++) {
        String key = (String) dataset2.getRowKey(i);
        key = StringUtils.substringAfter(key, GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY);
        Assert.assertNotNull("null series color", colors.get(key));
        Assert.assertEquals("series color", colors.get(key), renderer2.getSeriesPaint(i));
    }
    for (int i = 0; i < chart.getCategoryPlot().getFixedLegendItems().getItemCount(); i++) {
        LegendItem legendItem = chart.getCategoryPlot().getFixedLegendItems().get(i);
        Assert.assertNotNull("null series color", colors.get(legendItem.getLabel()));
        Assert.assertEquals("series color", colors.get(legendItem.getLabel()), legendItem.getFillPaint());
    }

    chartCountTest("summary.chart3", 1);
    chart = getChart("summary.chart3", 0);
    PiePlot plot3 = (PiePlot) chart.getPlot();
    PieDataset dataset3 = plot3.getDataset();
    for (int i = 0; i < dataset3.getItemCount(); i++) {
        String key = (String) dataset3.getKey(i);
        Assert.assertNotNull("null series color", colors.get(key));
        Assert.assertEquals("series color", colors.get(key), plot3.getSectionPaint(key));
    }

    chartCountTest("summary.chart4", 1);
    chart = getChart("summary.chart4", 0);
    XYItemRenderer renderer4 = chart.getXYPlot().getRenderer();
    XYDataset dataset4 = chart.getXYPlot().getDataset();
    for (int i = 0; i < dataset4.getSeriesCount(); i++) {
        String key = (String) dataset4.getSeriesKey(i);
        Assert.assertNotNull("null series color", colors.get(key));
        Assert.assertEquals("series color", colors.get(key), renderer4.getSeriesPaint(i));
    }
}

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 w  w  w  .j  a  v  a 2  s .  c  o m
                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]);
                }
            }
        }
    }
}