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:edu.ucla.stat.SOCR.chart.demo.RingChartDemo1.java

/**
 * Creates a chart./*www . j  av  a  2  s.co m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return a chart.
 */
protected JFreeChart createChart(PieDataset dataset) {

    JFreeChart chart = ChartFactory.createRingChart(chartTitle, // chart title
            dataset, // data
            !legendPanelOn, // include legend
            true, false);

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

    if (rotateOn) {
        Rotator rotator = new Rotator(plot);
        rotator.start();
    }

    setCategorySummary(dataset);
    return chart;

}

From source file:edu.ucla.stat.SOCR.chart.demo.PieChart3DDemo2.java

/**
 * Creates a demo chart./*www  . j a  va2s . c o  m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return A chart.
 */
protected JFreeChart createChart(PieDataset dataset) {
    // create the chart...
    JFreeChart chart = ChartFactory.createPieChart3D(chartTitle, // chart title
            dataset, // dataset
            !legendPanelOn, // include legend
            false, false);

    PiePlot3D plot = (PiePlot3D) chart.getPlot();
    plot.setStartAngle(270);
    plot.setDirection(Rotation.ANTICLOCKWISE);
    plot.setForegroundAlpha(0.60f);
    plot.setInteriorGap(0.05); // 0.33 used to work with JFreeChart 1.0.05

    for (int i = 0; i < pulloutFlag.length; i++) {
        //System.out.println("\""+pulloutFlag[i]+"\"");
        if (pulloutFlag[i].equals("1")) {
            Comparable key = dataset.getKey(i);
            plot.setExplodePercent(key, 0.30);
        }
    }

    if (rotateOn) {
        Rotator rotator = new Rotator(plot);
        rotator.start();
    }

    setCategorySummary(dataset);
    return chart;
}

From source file:edu.ucla.stat.SOCR.chart.demo.PieChart3DDemo3.java

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

    JFreeChart chart = ChartFactory.createPieChart3D(chartTitle, // chart title
            dataset, // data
            !legendPanelOn, // include legend
            true, false);

    PiePlot3D plot = (PiePlot3D) chart.getPlot();
    plot.setStartAngle(290);
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.5f);
    plot.setNoDataMessage("No data to display");
    plot.setLabelGenerator(new CustomPieSectionLabelGenerator());

    for (int i = 0; i < pulloutFlag.length; i++) {
        //System.out.println("\""+pulloutFlag[i]+"\"");
        if (pulloutFlag[i].equals("1")) {
            Comparable key = dataset.getKey(i);
            plot.setExplodePercent(key, 0.30);
        }
    }
    if (rotateOn) {
        Rotator rotator = new Rotator(plot);
        rotator.start();
    }
    setCategorySummary(dataset);
    return chart;

}

From source file:com.intel.stl.ui.common.view.ComponentFactory.java

/**
 * Create a simple pie chart without title, legend, label etc.
 * //from  www  .j  av a2  s. c o m
 * @param dataset
 *            the dataset to be renderer
 * @param colors
 *            an color array specify each item's color. The order of the
 *            array correspond to the item order in dataset
 * @return a pie chart
 */
public static JFreeChart createPlainPieChart(PieDataset dataset, Color[] colors) {
    if (dataset == null) {
        throw new IllegalArgumentException("No dataset.");
    }
    if (colors != null && colors.length != dataset.getItemCount()) {
        throw new IllegalArgumentException("Data have " + dataset.getItemCount() + " values, while we have "
                + colors.length + " colors for them.");
    }

    JFreeChart jfreechart = ChartFactory.createPieChart(null, dataset, false, true, false);
    PiePlot pieplot = (PiePlot) jfreechart.getPlot();
    if (colors != null) {
        for (int i = 0; i < colors.length; i++) {
            pieplot.setSectionPaint(dataset.getKey(i), colors[i]);
        }
    }
    pieplot.setBackgroundPaint(null);
    pieplot.setOutlineStroke(null);
    pieplot.setLabelGenerator(null);
    pieplot.setNoDataMessage(UILabels.STL40001_ERROR_No_DATA.getDescription());
    pieplot.setCircular(true);
    pieplot.setInteriorGap(0.000001);
    return jfreechart;
}

From source file:edu.ucla.stat.SOCR.chart.demo.PieChartDemo3.java

/**
 * Creates a demo chart.//from   w w  w  . ja v  a  2 s. c o  m
 * 
 * @param dataset  the dataset.
 * 
 * @return A chart.
 */
protected JFreeChart createChart(PieDataset dataset) {
    dataset = null;

    JFreeChart chart = ChartFactory.createPieChart(chartTitle, // chart title
            dataset, // data
            !legendPanelOn, // include legend
            true, false);

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setNoDataMessage("No data available so we go into this really "
            + "long spiel about what that means and it runs off the end of the "
            + "line but what can you do about that!");
    plot.setNoDataMessageFont(new Font("Serif", Font.ITALIC, 10));
    plot.setNoDataMessagePaint(Color.red);
    for (int i = 0; i < pulloutFlag.length; i++) {
        //System.out.println("\""+pulloutFlag[i]+"\"");
        if (isPullout(i)) {
            Comparable key = dataset.getKey(i);
            plot.setExplodePercent(key, 0.30);
        }
    }

    if (rotateOn) {
        Rotator rotator = new Rotator(plot);
        rotator.start();
    }

    setCategorySummary(dataset);
    return chart;
}

From source file:edu.ucla.stat.SOCR.chart.demo.PieChartDemo4.java

protected JFreeChart createChart(PieDataset dataset) {
    // create the chart...
    JFreeChart chart = ChartFactory.createPieChart(chartTitle, // chart title
            dataset, // dataset
            !legendPanelOn, // include legend
            true, false);//from w  w w  .j a va  2s.c o m

    // set the background color for the chart...
    chart.setBackgroundPaint(new Color(222, 222, 255));
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setCircular(true);
    for (int i = 0; i < pulloutFlag.length; i++) {
        //System.out.println("\""+pulloutFlag[i]+"\"");
        if (isPullout(i)) {
            Comparable key = dataset.getKey(i);
            plot.setExplodePercent(key, 0.30);
        }
    }
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {2}", NumberFormat.getNumberInstance(),
            NumberFormat.getPercentInstance()));
    plot.setNoDataMessage("No data available");

    if (rotateOn) {
        Rotator rotator = new Rotator(plot);
        rotator.start();
    }
    setCategorySummary(dataset);
    return chart;
}

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

/**
 *
 *///w w  w . j av a 2s  .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(0);
    piePlot.setShadowYOffset(0);
    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.AegeanChartTheme.java

/**
 *
 *//*from w w  w  . j a  va2 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.07);
    //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.AegeanChartTheme.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);
    }//  w w w.jav  a2 s.c  om
    piePlot.setShadowXOffset(0);
    piePlot.setShadowYOffset(0);
    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.AegeanChartTheme.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  www  .  j av  a  2  s .  com
    piePlot3D.setDarkerSides(true);
    piePlot3D.setDepthFactor(0.07);
    //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;
}