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

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

Introduction

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

Prototype

public void setCircular(boolean flag) 

Source Link

Document

A flag indicating whether the pie chart is circular, or stretched into an elliptical shape.

Usage

From source file:servlets.LeasingControllerServlet.java

public void doGetChart() {
    PieDataset pieDataset = createDataset();
    JFreeChart chart = ChartFactory.createPieChart("Tenant Mix ", pieDataset, true, true, false);
    //chart.setBackgroundPaint(new Color(222, 222, 255));
    final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {2}"));
    plot.setCircular(true);
    plot.setSectionPaint("F&B", new Color(15, 192, 252));
    try {// w ww.  jav  a  2s .  co  m
        final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        final File file1 = new File(
                getServletContext().getRealPath("") + "/leasingSystem/leasingSystemAssets/chart/piechart.png");
        ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);
    } catch (Exception e) {
        System.out.println(e);

    }
}

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

/**
 * Creates a chart.//from  w  w  w .j  a v  a2  s .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:edu.ucla.stat.SOCR.applications.demo.PortfolioApplication2.java

protected JFreeChart createEmptyChart(String chartTitle, PieDataset dataset) {

    JFreeChart chart = ChartFactory.createPieChart(chartTitle, // chart title
            null, // data
            true, // include legend
            true, false);/*  ww  w.  j a va 2  s  .co m*/

    PiePlot plot = (PiePlot) chart.getPlot();
    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:net.sf.fspdfs.chartthemes.spring.AegeanChartTheme.java

/**
 *
 *//* www .j  av a  2  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(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:org.jfree.chart.demo.JFreeChartDemoBase.java

/**
 * Creates and returns a sample pie chart.
 *
 * @return a sample pie chart.//from w  ww  .j a va 2s. c  om
 */
public JFreeChart createPieChartOne() {

    // create a default chart based on some sample data...
    final String title = this.resources.getString("pie.pie1.title");
    final CategoryDataset data = DemoDatasetFactory.createCategoryDataset();
    final PieDataset extracted = DatasetUtilities.createPieDatasetForRow(data, 0);
    final JFreeChart chart = ChartFactory.createPieChart(title, extracted, true, true, false);

    // then customise it a little...
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.orange));
    final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setCircular(false);
    // make section 1 explode by 100%...
    plot.setExplodePercent(1, 1.00);
    return chart;

}

From source file:org.pentaho.chart.plugin.jfreechart.JFreeChartFactoryEngine.java

public JFreeChart makePieChart(ChartModel chartModel, NamedValuesDataModel dataModel,
        final IChartLinkGenerator linkGenerator) {
    final DefaultPieDataset dataset = new DefaultPieDataset();
    for (NamedValue namedValue : dataModel) {
        if (namedValue.getName() != null) {
            dataset.setValue(namedValue.getName(),
                    scaleNumber(namedValue.getValue(), dataModel.getScalingFactor()));
        }/*  w  ww. j av a  2 s  . c  o m*/
    }

    boolean showLegend = (chartModel.getLegend() != null) && (chartModel.getLegend().getVisible());

    String title = "";
    if ((chartModel.getTitle() != null) && (chartModel.getTitle().getText() != null)
            && (chartModel.getTitle().getText().trim().length() > 0)) {
        title = chartModel.getTitle().getText();
    }

    final JFreeChart chart = ChartFactory.createPieChart(title, dataset, showLegend, true, false);

    initChart(chart, chartModel);

    final PiePlot jFreePiePlot = (PiePlot) chart.getPlot();

    if (linkGenerator != null) {
        jFreePiePlot.setURLGenerator(new PieURLGenerator() {

            public String generateURL(PieDataset arg0, Comparable arg1, int arg2) {
                return linkGenerator.generateLink(arg1.toString(), arg1.toString(), arg0.getValue(arg1));
            }
        });
    }

    jFreePiePlot.setNoDataMessage("No data available"); //$NON-NLS-1$
    jFreePiePlot.setCircular(true);
    jFreePiePlot.setLabelGap(0.02);

    org.pentaho.chart.model.PiePlot chartBeansPiePlot = (org.pentaho.chart.model.PiePlot) chartModel.getPlot();

    List<Integer> colors = getPlotColors(chartBeansPiePlot);

    int index = 0;
    for (NamedValue namedValue : dataModel) {
        if (namedValue.getName() != null) {
            jFreePiePlot.setSectionPaint(namedValue.getName(),
                    new Color(0x00FFFFFF & colors.get(index % colors.size())));
        }
        index++;
    }

    if (chartBeansPiePlot.getLabels().getVisible()) {
        jFreePiePlot.setLabelGenerator(new StandardPieSectionLabelGenerator());

        Font font = ChartUtils.getFont(chartBeansPiePlot.getLabels().getFontFamily(),
                chartBeansPiePlot.getLabels().getFontStyle(), chartBeansPiePlot.getLabels().getFontWeight(),
                chartBeansPiePlot.getLabels().getFontSize());
        if (font != null) {
            jFreePiePlot.setLabelFont(font);
            if (chartBeansPiePlot.getLabels().getColor() != null) {
                jFreePiePlot.setLabelPaint(new Color(0x00FFFFFF & chartBeansPiePlot.getLabels().getColor()));
            }
            if (chartBeansPiePlot.getLabels().getBackgroundColor() != null) {
                jFreePiePlot.setLabelBackgroundPaint(
                        new Color(0x00FFFFFF & chartBeansPiePlot.getLabels().getBackgroundColor()));
            }
        }
    } else {
        jFreePiePlot.setLabelGenerator(null);
    }

    jFreePiePlot.setStartAngle(-chartBeansPiePlot.getStartAngle());

    return chart;
}

From source file:com.manydesigns.portofino.chart.Chart1DGenerator.java

public JFreeChart generate(ChartDefinition chartDefinition, Persistence persistence, Locale locale) {
    DefaultPieDataset dataset = new DefaultPieDataset();
    java.util.List<Object[]> result;
    String query = chartDefinition.getQuery();
    logger.info(query);//from ww w .j  ava 2s.c  o  m
    Session session = persistence.getSession(chartDefinition.getDatabase());
    result = QueryUtils.runSql(session, query);
    for (Object[] current : result) {
        ComparableWrapper key = new ComparableWrapper((Comparable) current[0]);
        dataset.setValue(key, (Number) current[1]);
        if (current.length > 2) {
            key.setLabel(current[2].toString());
        }
    }

    JFreeChart chart = createChart(chartDefinition, dataset);

    chart.setAntiAlias(isAntiAlias());

    // impostiamo il bordo invisibile
    // eventualmente e' il css a fornirne uno
    // eventualmente e' il css a fornirne uno
    chart.setBorderVisible(isBorderVisible());

    // impostiamo il titolo
    TextTitle title = chart.getTitle();
    title.setFont(titleFont);
    title.setMargin(10.0, 0.0, 0.0, 0.0);

    // ottieni il Plot
    PiePlot plot = (PiePlot) chart.getPlot();

    String urlExpression = chartDefinition.getUrlExpression();
    if (!StringUtils.isBlank(urlExpression)) {
        PieURLGenerator urlGenerator = new ChartPieUrlGenerator(urlExpression);
        plot.setURLGenerator(urlGenerator);
    } else {
        plot.setURLGenerator(null);
    }

    // il plot ha sfondo e bordo trasparente
    // (quindi si vede il colore del chart)
    plot.setBackgroundPaint(transparentColor);
    plot.setOutlinePaint(transparentColor);

    // Modifico il toolTip
    // hongliangpan add
    // :?{0}  {1}  {2} ? ,???
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})",
            NumberFormat.getNumberInstance(), new DecimalFormat("0.00%")));
    // {0}={1}({2})
    plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}"));
    // ?(0.0-1.0)
    // plot.setForegroundAlpha(1.0f);
    // imposta la distanza delle etichette dal plot
    plot.setLabelGap(0.03);
    // plot.setLabelGenerator(new MyPieSectionLabelGenerator());

    // imposta il messaggio se non ci sono dati
    plot.setNoDataMessage(ElementsThreadLocals.getText("no.data.available"));

    plot.setCircular(true);

    plot.setBaseSectionOutlinePaint(Color.BLACK);

    DrawingSupplier supplier = new DesaturatedDrawingSupplier(plot.getDrawingSupplier());
    plot.setDrawingSupplier(supplier);
    // ?
    plot.setForegroundAlpha(1.0f);
    // impostiamo il titolo della legenda
    String legendString = chartDefinition.getLegend();
    Title subtitle = new TextTitle(legendString, legendFont, Color.BLACK, RectangleEdge.BOTTOM,
            HorizontalAlignment.CENTER, VerticalAlignment.CENTER, new RectangleInsets(0, 0, 0, 0));
    subtitle.setMargin(0, 0, 5, 0);
    chart.addSubtitle(subtitle);

    // impostiamo la legenda
    LegendTitle legend = chart.getLegend();
    legend.setBorder(0, 0, 0, 0);
    legend.setItemFont(legendItemFont);
    int legendMargin = 10;
    legend.setMargin(0.0, legendMargin, legendMargin, legendMargin);
    legend.setBackgroundPaint(transparentColor);

    // impostiamo un gradiente orizzontale
    Paint chartBgPaint = new GradientPaint(0, 0, new Color(255, 253, 240), 0, getHeight(), Color.WHITE);
    chart.setBackgroundPaint(chartBgPaint);
    return chart;
}

From source file:com.rapidminer.gui.plotter.charts.AbstractPieChartPlotter.java

public void updatePlotter() {
    int categoryCount = prepareData();
    String maxClassesProperty = ParameterService
            .getParameterValue(MainFrame.PROPERTY_RAPIDMINER_GUI_PLOTTER_LEGEND_CLASSLIMIT);
    int maxClasses = 20;
    try {/*  ww  w.j  a  v  a 2  s.c  om*/
        if (maxClassesProperty != null) {
            maxClasses = Integer.parseInt(maxClassesProperty);
        }
    } catch (NumberFormatException e) {
        // LogService.getGlobal().log("Pie Chart plotter: cannot parse property 'rapidminer.gui.plotter.colors.classlimit', using maximal 20 different classes.",
        // LogService.WARNING);
        LogService.getRoot().log(Level.WARNING,
                "com.rapidminer.gui.plotter.charts.AbstractPieChartPlotter.pie_chart_plotter_parsing_error");
    }
    boolean createLegend = categoryCount > 0 && categoryCount < maxClasses;

    if (categoryCount <= MAX_CATEGORIES) {
        JFreeChart chart = createChart(pieDataSet, createLegend);

        // set the background color for the chart...
        chart.setBackgroundPaint(Color.white);

        PiePlot plot = (PiePlot) chart.getPlot();

        plot.setBackgroundPaint(Color.WHITE);
        plot.setSectionOutlinesVisible(true);
        plot.setShadowPaint(new Color(104, 104, 104, 100));

        int size = pieDataSet.getKeys().size();
        for (int i = 0; i < size; i++) {
            Comparable<?> key = pieDataSet.getKey(i);
            plot.setSectionPaint(key, getColorProvider(true).getPointColor(i / (double) (size - 1)));

            boolean explode = false;
            for (String explosionGroup : explodingGroups) {
                if (key.toString().startsWith(explosionGroup) || explosionGroup.startsWith(key.toString())) {
                    explode = true;
                    break;
                }
            }

            if (explode) {
                plot.setExplodePercent(key, this.explodingAmount);
            }
        }

        plot.setLabelFont(LABEL_FONT);
        plot.setNoDataMessage("No data available");
        plot.setCircular(false);
        plot.setLabelGap(0.02);
        plot.setOutlinePaint(Color.WHITE);

        // legend settings
        LegendTitle legend = chart.getLegend();
        if (legend != null) {
            legend.setPosition(RectangleEdge.TOP);
            legend.setFrame(BlockBorder.NONE);
            legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
            legend.setItemFont(LABEL_FONT);
        }

        if (panel instanceof AbstractChartPanel) {
            panel.setChart(chart);
        } else {
            panel = new AbstractChartPanel(chart, getWidth(), getHeight() - MARGIN);
            final ChartPanelShiftController controller = new ChartPanelShiftController(panel);
            panel.addMouseListener(controller);
            panel.addMouseMotionListener(controller);
        }

        // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!!
        panel.getChartRenderingInfo().setEntityCollection(null);
    } else {
        // LogService.getGlobal().logNote("Too many columns (" + categoryCount +
        // "), this chart is only able to plot up to " + MAX_CATEGORIES +
        // " different categories.");
        LogService.getRoot().log(Level.INFO,
                "com.rapidminer.gui.plotter.charts.AbstractPieChartPlotter.too_many_columns",
                new Object[] { categoryCount, MAX_CATEGORIES });
    }
}

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 .  ja v a 2 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:fr.inria.soctrace.framesoc.ui.piechart.view.StatisticsPieChartView.java

/**
 * Creates the chart./*from   w  ww.  j  a  v a  2 s .c  o m*/
 * 
 * @param dataset
 *            the dataset.
 * @param loader
 *            the pie chart loader
 * @param dataRequested
 *            flag indicating if the data have been requested for the current loader and the
 *            current interval
 * @return the pie chart
 */
private JFreeChart createChart(PieDataset dataset, String title, IPieChartLoader loader,
        boolean dataRequested) {

    JFreeChart chart = ChartFactory.createPieChart(title, dataset, HAS_LEGEND, HAS_TOOLTIPS, HAS_URLS);

    // legend
    if (HAS_LEGEND) {
        LegendTitle legend = chart.getLegend();
        legend.setPosition(RectangleEdge.LEFT);
    }

    // plot
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setSectionOutlinesVisible(false);
    plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    plot.setNoDataMessage(
            "No data available " + (dataRequested ? "in this time interval" : "yet. Press the Load button."));
    plot.setCircular(true);
    plot.setLabelGenerator(null); // hide labels
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlineVisible(false);
    plot.setShadowPaint(Color.WHITE);
    plot.setBaseSectionPaint(Color.WHITE);
    StandardPieToolTipGenerator g = (StandardPieToolTipGenerator) plot.getToolTipGenerator();
    NumberFormat format = ValueLabelProvider.getActualFormat(loader.getFormat(), getTimeUnit());
    StandardPieToolTipGenerator sg = new StandardPieToolTipGenerator(g.getLabelFormat(), format,
            g.getPercentFormat());
    plot.setToolTipGenerator(sg);

    for (Object o : dataset.getKeys()) {
        String key = (String) o;
        plot.setSectionPaint(key, loader.getColor(key).getAwtColor());
    }
    return chart;
}