Example usage for org.jfree.data.general PieDataset getKey

List of usage examples for org.jfree.data.general PieDataset getKey

Introduction

In this page you can find the example usage for org.jfree.data.general PieDataset getKey.

Prototype

public Comparable getKey(int index);

Source Link

Document

Returns the key associated with the item at a given position.

Usage

From source file:org.codehaus.mojo.dashboard.report.plugin.chart.PieChartRenderer.java

public void createChart() {

    PieDataset dataset = (PieDataset) this.datasetStrategy.getDataset();
    report = ChartFactory.createPieChart(this.datasetStrategy.getTitle(), dataset, true, true, false);
    PiePlot plot = (PiePlot) report.getPlot();
    //        plot.setCircular( false );
    plot.setDirection(Rotation.ANTICLOCKWISE);
    /*//from   w  w w  .ja va 2 s . com
     * plot.setExplodePercent(0, 0.15D); plot.setExplodePercent(1, 0.15D);
     */
    //        plot.setInteriorGap( PieChartRenderer.INTERIOR_GAP );
    plot.setLabelFont(new Font("Lucida", 0, PieChartRenderer.FONT_SIZE));
    plot.setLabelGap(PieChartRenderer.LABEL_GAP);
    plot.setNoDataMessage("No data available");
    plot.setStartAngle(PieChartRenderer.START_ANGLE);
    Paint[] paints = this.datasetStrategy.getPaintColor();

    for (int i = 0; i < dataset.getItemCount() && i < paints.length; i++) {
        plot.setSectionPaint(dataset.getKey(i), paints[i]);
    }
}

From source file:org.jfree.eastwood.ChartEngine.java

private static void applyColorsToPiePlot(PiePlot plot, Color[] colors) {
    if (colors.length == 1) {
        Color c = colors[0];//from ww  w  . j a  va 2s . co  m
        colors = new Color[2];
        colors[0] = c;
        colors[1] = new Color(255 - ((255 - c.getRed()) / 5), 255 - ((255 - c.getGreen()) / 5),
                255 - ((255 - c.getBlue()) / 5));
    }
    PieDataset dataset = plot.getDataset();
    int sectionCount = dataset.getItemCount();
    if (colors.length < sectionCount) { // we need to interpolate some
                                        // colors
        for (int i = 0; i < colors.length - 1; i++) {
            Color c1 = colors[i];
            Color c2 = colors[i + 1];
            int s1 = sectionIndexForColor(i, colors.length, sectionCount);
            int s2 = sectionIndexForColor(i + 1, colors.length, sectionCount);
            for (int s = s1; s <= s2; s++) {
                Color c = interpolatedColor(c1, c2, s - s1, s2 - s1);
                plot.setSectionPaint(dataset.getKey(s), c);
            }
        }
    } else {
        for (int i = 0; i < sectionCount; i++) {
            plot.setSectionPaint(dataset.getKey(i), colors[i]);
        }
    }
}

From source file:com.ouc.cpss.view.SupTradeChartBuilder.java

private static JFreeChart createJFreeChart(PieDataset dataset) {
    /**/*  w w w . j  a  va  2s .  c o m*/
     * JFreeChart
     */
    //?     
    StandardChartTheme standardChartTheme = new StandardChartTheme("CN");
    //     
    standardChartTheme.setExtraLargeFont(new Font("", Font.BOLD, 20));
    //    
    standardChartTheme.setRegularFont(new Font("", Font.PLAIN, 15));
    //?     
    standardChartTheme.setLargeFont(new Font("", Font.PLAIN, 15));
    //?   
    ChartFactory.setChartTheme(standardChartTheme);
    //??  
    //createPieChart 2D; createPieChart3D  3D
    JFreeChart chart = ChartFactory.createPieChart("", dataset, true, true, false);

    //,?
    chart.setTitle(new TextTitle("", new Font("", Font.ITALIC, 22)));

    //?
    LegendTitle legend = chart.getLegend(0);
    //,ture,?
    legend.setItemFont(new Font("", Font.BOLD, 20));

    //?(??)
    PiePlot plot = (PiePlot) chart.getPlot();
    //?==?
    plot.setLabelFont(new Font("", Font.BOLD, 22));
    //
    plot.setBaseSectionOutlinePaint(Color.BLUE);
    //
    plot.setBaseSectionOutlineStroke(new BasicStroke(0.5f));
    //?,??,??
    plot.setDirection(Rotation.CLOCKWISE);//,Rotation.CLOCKWISE
    //()
    plot.setStartAngle(70);
    //???
    //plot.setExplodePercent(1, 0.5D);
    //plot.setExplodePercent("One", 0.5D);
    //,3D?
    plot.setExplodePercent(dataset.getKey(0), 0.1d);
    //
    plot.setLabelLinkPaint(Color.BLUE);
    //
    plot.setLabelOutlinePaint(Color.black);
    //
    plot.setLabelShadowPaint(Color.RED);
    //
    plot.setSectionPaint(1, Color.BLACK);
    // :,{0},{1},{2}?,???
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}:{1}\r\n{2}",
            NumberFormat.getNumberInstance(), new DecimalFormat("0.00%")));

    //
    plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}={2}"));
    //:(true),(false)
    plot.setCircular(true);
    //?
    plot.setNoDataMessage("??...");

    //???
    plot.setToolTipGenerator(new StandardPieToolTipGenerator());
    //
    //plot.setURLGenerator(new StandardPieURLGenerator("detail.jsp"));

    return chart;
}

From source file:net.sf.fspdfs.chartthemes.spring.EyeCandySixtiesChartTheme.java

/**
 *
 *//*from w  w w .  j a  v  a2 s . c  o  m*/
protected JFreeChart createPieChart() throws JRException {
    JFreeChart jfreeChart = super.createPieChart();

    PiePlot piePlot = (PiePlot) jfreeChart.getPlot();
    piePlot.setLabelBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT);
    piePlot.setLabelShadowPaint(ChartThemesConstants.TRANSPARENT_PAINT);
    piePlot.setLabelOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT);
    piePlot.setShadowXOffset(5);
    piePlot.setShadowYOffset(10);
    piePlot.setShadowPaint(new GradientPaint(0, getChart().getHeight() / 2, new Color(41, 120, 162), 0,
            getChart().getHeight(), Color.white));
    PieDataset pieDataset = piePlot.getDataset();
    if (pieDataset != null) {
        for (int i = 0; i < pieDataset.getItemCount(); i++) {
            piePlot.setSectionOutlinePaint(pieDataset.getKey(i), ChartThemesConstants.TRANSPARENT_PAINT);
            //makes pie colors darker
            //piePlot.setSectionPaint(pieDataset.getKey(i), GRADIENT_PAINTS[i]);
        }
    }

    piePlot.setCircular(true);
    return jfreeChart;
}

From source file:net.sf.fspdfs.chartthemes.spring.EyeCandySixtiesChartTheme.java

/**
 *
 *///from   w w w .  ja  v a 2  s .c o m
protected JFreeChart createPie3DChart() throws JRException {
    JFreeChart jfreeChart = super.createPie3DChart();

    PiePlot3D piePlot3D = (PiePlot3D) jfreeChart.getPlot();
    piePlot3D.setLabelBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT);
    piePlot3D.setLabelShadowPaint(ChartThemesConstants.TRANSPARENT_PAINT);
    piePlot3D.setLabelOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT);
    piePlot3D.setDarkerSides(true);
    piePlot3D.setDepthFactor(0.1);
    // does not work for 3D
    //      piePlot3D.setShadowXOffset(5);
    //      piePlot3D.setShadowYOffset(10);
    //      piePlot3D.setShadowPaint(new GradientPaint(
    //            0,
    //            getChart().getHeight() / 2,
    //            new Color(41, 120, 162),
    //            0,
    //            getChart().getHeight(),
    //            Color.white)
    //      );

    PieDataset pieDataset = piePlot3D.getDataset();
    if (pieDataset != null) {
        for (int i = 0; i < pieDataset.getItemCount(); i++) {
            piePlot3D.setSectionOutlinePaint(pieDataset.getKey(i), ChartThemesConstants.TRANSPARENT_PAINT);
        }
    }

    piePlot3D.setCircular(true);
    return jfreeChart;
}

From source file:net.sf.jasperreports.chartthemes.spring.EyeCandySixtiesChartTheme.java

@Override
protected JFreeChart createPieChart() throws JRException {
    JFreeChart jfreeChart = super.createPieChart();
    PiePlot piePlot = (PiePlot) jfreeChart.getPlot();
    JRPiePlot jrPiePlot = (JRPiePlot) getPlot();
    boolean isShowLabels = jrPiePlot.getShowLabels() == null ? true : jrPiePlot.getShowLabels();

    if (isShowLabels && piePlot.getLabelGenerator() != null) {
        piePlot.setLabelBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT);
        piePlot.setLabelShadowPaint(ChartThemesConstants.TRANSPARENT_PAINT);
        piePlot.setLabelOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT);
    }/*from  w ww.  jav  a 2s.co m*/
    piePlot.setShadowXOffset(5);
    piePlot.setShadowYOffset(10);
    piePlot.setShadowPaint(new GradientPaint(0, getChart().getHeight() / 2, new Color(41, 120, 162), 0,
            getChart().getHeight(), Color.white));
    PieDataset pieDataset = piePlot.getDataset();
    if (pieDataset != null) {
        for (int i = 0; i < pieDataset.getItemCount(); i++) {
            piePlot.setSectionOutlinePaint(pieDataset.getKey(i), ChartThemesConstants.TRANSPARENT_PAINT);
            //makes pie colors darker
            //piePlot.setSectionPaint(pieDataset.getKey(i), GRADIENT_PAINTS[i]);
        }
    }

    piePlot.setCircular(true);
    return jfreeChart;
}

From source file:net.sf.jasperreports.chartthemes.spring.EyeCandySixtiesChartTheme.java

@Override
protected JFreeChart createPie3DChart() throws JRException {
    JFreeChart jfreeChart = super.createPie3DChart();

    PiePlot3D piePlot3D = (PiePlot3D) jfreeChart.getPlot();
    JRPie3DPlot jrPiePlot = (JRPie3DPlot) getPlot();
    boolean isShowLabels = jrPiePlot.getShowLabels() == null ? true : jrPiePlot.getShowLabels();
    if (isShowLabels && piePlot3D.getLabelGenerator() != null) {
        piePlot3D.setLabelBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT);
        piePlot3D.setLabelShadowPaint(ChartThemesConstants.TRANSPARENT_PAINT);
        piePlot3D.setLabelOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT);
    }//from w ww. jav  a 2 s .co m
    piePlot3D.setDarkerSides(true);
    piePlot3D.setDepthFactor(0.1);
    // does not work for 3D
    //      piePlot3D.setShadowXOffset(5);
    //      piePlot3D.setShadowYOffset(10);
    //      piePlot3D.setShadowPaint(new GradientPaint(
    //            0,
    //            getChart().getHeight() / 2,
    //            new Color(41, 120, 162),
    //            0,
    //            getChart().getHeight(),
    //            Color.white)
    //      );

    PieDataset pieDataset = piePlot3D.getDataset();
    if (pieDataset != null) {
        for (int i = 0; i < pieDataset.getItemCount(); i++) {
            piePlot3D.setSectionOutlinePaint(pieDataset.getKey(i), ChartThemesConstants.TRANSPARENT_PAINT);
        }
    }

    piePlot3D.setCircular(true);
    return jfreeChart;
}

From source file:edu.ucla.stat.SOCR.chart.SuperPieChart.java

/**
 * Creates a chart.//ww w.  java 2s. co m
 * 
 * @param dataset  the dataset.
 * 
 * @return a chart.
 */
protected JFreeChart createChart(PieDataset dataset) {

    JFreeChart chart = ChartFactory.createPieChart(chartTitle, // chart title
            dataset, // data
            !legendPanelOn, // include legend
            true, false);
    TextTitle title = chart.getTitle();
    title.setToolTipText("A title tooltip!");

    PiePlot plot = (PiePlot) chart.getPlot();
    if (!ThreeDPie) {
        for (int i = 0; i < pulloutFlag.length; i++) {
            //System.out.println("SuperPieChart\""+pulloutFlag[i]+"\"");
            if (pulloutFlag[i].equals("1")) {
                Comparable key = dataset.getKey(i);
                plot.setExplodePercent(key, 0.30);
            }
        }
    }
    plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    plot.setNoDataMessage("No data available");
    plot.setCircular(false);
    plot.setLabelGap(0.02);

    return chart;
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.PieChartExpression.java

protected void configureChart(final JFreeChart chart) {
    super.configureChart(chart);

    final Plot plot = chart.getPlot();
    final PiePlot pp = (PiePlot) plot;
    final PieDataset pieDS = pp.getDataset();
    pp.setDirection(rotationClockwise ? Rotation.CLOCKWISE : Rotation.ANTICLOCKWISE);
    if ((explodeSegment != null) && (explodePct != null)) {
        configureExplode(pp);/*from www  .  ja  v a 2s .  c  o  m*/
    }
    if (StringUtils.isEmpty(getTooltipFormula()) == false) {
        pp.setToolTipGenerator(new FormulaPieTooltipGenerator(getRuntime(), getTooltipFormula()));
    }
    if (StringUtils.isEmpty(getUrlFormula()) == false) {
        pp.setURLGenerator(new FormulaPieURLGenerator(getRuntime(), getUrlFormula()));
    }

    pp.setIgnoreNullValues(ignoreNulls);
    pp.setIgnoreZeroValues(ignoreZeros);
    if (Boolean.FALSE.equals(getItemsLabelVisible())) {
        pp.setLabelGenerator(null);
    } else {
        final ExpressionRuntime runtime = getRuntime();
        final Locale locale = runtime.getResourceBundleFactory().getLocale();

        final FastDecimalFormat fastPercent = new FastDecimalFormat(FastDecimalFormat.TYPE_PERCENT, locale);
        final FastDecimalFormat fastInteger = new FastDecimalFormat(FastDecimalFormat.TYPE_INTEGER, locale);

        final DecimalFormat numFormat = new DecimalFormat(fastInteger.getPattern(),
                new DecimalFormatSymbols(locale));
        numFormat.setRoundingMode(RoundingMode.HALF_UP);

        final DecimalFormat percentFormat = new DecimalFormat(fastPercent.getPattern(),
                new DecimalFormatSymbols(locale));
        percentFormat.setRoundingMode(RoundingMode.HALF_UP);

        final StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator(pieLabelFormat,
                numFormat, percentFormat);
        pp.setLabelGenerator(labelGen);

        final StandardPieSectionLabelGenerator legendGen = new StandardPieSectionLabelGenerator(
                pieLegendLabelFormat, numFormat, percentFormat);
        pp.setLegendLabelGenerator(legendGen);
    }

    if (StringUtils.isEmpty(getLabelFont()) == false) {
        pp.setLabelFont(Font.decode(getLabelFont()));
    }

    if (pieDS != null) {
        final String[] colors = getSeriesColor();
        for (int i = 0; i < colors.length; i++) {
            if (i < pieDS.getItemCount()) {
                pp.setSectionPaint(pieDS.getKey(i), parseColorFromString(colors[i]));
            } else {
                break;
            }
        }
    }

    if (shadowPaint != null) {
        pp.setShadowPaint(shadowPaint);
    }
    if (shadowXOffset != null) {
        pp.setShadowXOffset(shadowXOffset.doubleValue());
    }
    if (shadowYOffset != null) {
        pp.setShadowYOffset(shadowYOffset.doubleValue());
    }
    pp.setCircular(circular);

    if (isShowBorder() == false || isChartSectionOutline() == false) {
        chart.setBorderVisible(false);
        chart.getPlot().setOutlineVisible(false);
    }

}

From source file:org.openfaces.component.chart.impl.plots.PiePlotAdapter.java

private void sectorProcessing(PiePlot plot, PieChartView chartView, PieDataset dataset,
        CategoryDataset categoryDataset) {
    List<PieSectorProperties> sectors = chartView.getSectors();
    if (sectors == null || sectors.size() == 0)
        return;//from  w w  w.  ja v  a  2  s .c o m

    for (PieSectorProperties sector : sectors) {
        DynamicPieGenerator generator = new DynamicPieGenerator(chartView, null);

        int index = -1;

        Float sectorPulled = sector.getPulled();
        if (dataset instanceof CategoryToPieDataset) {
            CategoryToPieDataset cds = (CategoryToPieDataset) dataset;
            int count = getIterationCount(cds);
            for (int q = 0; q < count; q++) {
                CategoryToPieDataset currPieDataset = new CategoryToPieDataset(categoryDataset, order, q);
                List keys = currPieDataset.getKeys();
                index = -1;
                for (int j = 0; j < keys.size(); j++) {
                    index++;

                    boolean conditionValue = generator.getConditionValue(sector, q, currPieDataset,
                            currPieDataset.getKey(j));
                    if (!conditionValue)
                        continue;

                    if (sectorPulled != null && sectorPulled > 0) {
                        plot.setExplodePercent(index, (double) sectorPulled);
                    }

                    StyleObjectModel cssSectorModel = sector.getStyleObjectModel();
                    if (cssSectorModel != null && cssSectorModel.getBorder() != null) {
                        StyleBorderModel border = cssSectorModel.getBorder();
                        Color borderColor = border.getColor();
                        if (borderColor != null) {
                            plot.setSectionOutlinePaint(index, borderColor);
                            plot.setSectionOutlineStroke(index, PropertiesConverter.toStroke(border));
                        }

                        Color sectorModelColor = cssSectorModel.getColor();
                        if (sectorModelColor != null) {
                            plot.setSectionPaint(index, sectorModelColor);
                        }
                    }
                }
            }
        } else {
            if (dataset == null || dataset.getKeys() == null)
                continue;

            for (int j = 0; j < dataset.getKeys().size(); j++) {
                index++;

                boolean conditionValue = generator.getConditionValue(sector, 0, dataset, dataset.getKey(j));
                if (!conditionValue)
                    continue;

                if (sectorPulled != null && sectorPulled > 0) {
                    plot.setExplodePercent(index, (double) sectorPulled);
                }

                StyleObjectModel cssSectorModel = sector.getStyleObjectModel();
                if (cssSectorModel != null && cssSectorModel.getBorder() != null) {
                    StyleBorderModel border = cssSectorModel.getBorder();
                    if (border.getColor() != null) {
                        plot.setSectionOutlinePaint(index, border.getColor());
                        plot.setSectionOutlineStroke(index, PropertiesConverter.toStroke(border));
                    }

                }
                if (cssSectorModel != null && cssSectorModel.getColor() != null) {
                    plot.setSectionPaint(index, cssSectorModel.getColor());
                }
            }
        }

    }

}