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

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

Introduction

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

Prototype

public void setBackgroundPaint(Paint paint) 

Source Link

Document

Sets the background color of the plot area and sends a PlotChangeEvent to all registered listeners.

Usage

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

/**
 * Creates a pie chart.// w  w  w.j  a  va  2  s .  c om
 *
 * @return A pie chart.
 */
private static JFreeChart createPieChart() {
    JFreeChart chart = ChartFactory.createPieChart(null, null, false, true, false);
    chart.setBackgroundPaint(Color.white);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setInsets(RectangleInsets.ZERO_INSETS);
    plot.setInteriorGap(0.06);
    plot.setStartAngle(0.0);
    plot.setLabelGenerator(null);
    plot.setBaseSectionOutlinePaint(Color.white);
    plot.setBaseSectionOutlineStroke(new BasicStroke(1.2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    plot.setOutlineVisible(false);
    plot.setLabelBackgroundPaint(null);
    plot.setLabelOutlinePaint(null);
    plot.setLabelShadowPaint(null);
    plot.setLabelPadding(RectangleInsets.ZERO_INSETS);
    plot.setLabelFont(new Font("Dialog", Font.PLAIN, 12));
    plot.setLabelPaint(Color.darkGray);
    plot.setToolTipGenerator(new StandardPieToolTipGenerator("{2}"));
    return chart;
}

From source file:org.gephi.desktop.partition.PartitionPie.java

public void setup(Partition partition) {
    data = new DefaultPieDataset();
    for (Part p : partition.getParts()) {
        data.setValue(p.getDisplayName(), p.getPercentage());
    }//ww  w  . j a va 2s.  co m
    final JFreeChart chart = ChartFactory.createPieChart("test", data, false, false, false);
    chart.setTitle(new TextTitle());
    chart.setBackgroundPaint(null);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setShadowPaint(null);
    //plot.setSimpleLabels(true);
    plot.setLabelBackgroundPaint(Color.WHITE);
    plot.setLabelOutlineStroke(null);
    plot.setLabelShadowPaint(null);
    plot.setOutlineVisible(false);
    plot.setLabelFont(new java.awt.Font("Tahoma", 0, 10));
    plot.setLabelPaint(Color.BLACK);
    //plot.setLabelGap(0.05);
    plot.setCircular(true);
    plot.setBackgroundPaint(null);
    plot.setBackgroundAlpha(1f);
    for (Part p : partition.getParts()) {
        plot.setSectionPaint(p.getDisplayName(), p.getColor());
    }
    chartPanel = new ChartPanel(chart, true);
    chartPanel.setOpaque(false);
    chartPanel.setPopupMenu(null);
    add(chartPanel, BorderLayout.CENTER);
}

From source file:org.gephi.desktop.context.ContextPieChart.java

public ContextPieChart() {
    data = new DefaultPieDataset();
    final JFreeChart chart = ChartFactory.createPieChart("Employee Survey", data, false, false, false);
    chart.setTitle(new TextTitle());
    chart.setBackgroundPaint(null);/*from ww w . j av  a  2  s. c om*/
    chart.setPadding(new RectangleInsets(0, 0, 0, 0));
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setShadowPaint(null);
    plot.setSimpleLabels(true);
    plot.setLabelBackgroundPaint(null);
    plot.setLabelOutlineStroke(null);
    plot.setLabelShadowPaint(null);
    plot.setOutlineVisible(false);
    plot.setLabelFont(new java.awt.Font("Tahoma", 0, 10));
    plot.setLabelPaint(Color.WHITE);
    plot.setLabelGap(0.5);
    plot.setCircular(true);
    plot.setInteriorGap(0);
    plot.setBackgroundPaint(null);
    plot.setBackgroundAlpha(1f);
    plot.setSectionPaint(NbBundle.getMessage(getClass(), "ContextPieChart.visible"), new Color(0x222222));
    plot.setSectionPaint(NbBundle.getMessage(getClass(), "ContextPieChart.notVisible"), new Color(0xDDDDDD));
    chartPanel = new ChartPanel(chart, 100, 100, 10, 10, 300, 300, true, false, false, false, false, false);
    ((FlowLayout) chartPanel.getLayout()).setHgap(0);
    ((FlowLayout) chartPanel.getLayout()).setVgap(0);
    chartPanel.setOpaque(false);
    chartPanel.setPopupMenu(null);
}

From source file:aplicarFiltros.PanelResultado.java

public void graficar() {

    //Grafico de cantidad de Pixeles
    JFreeChart chartPixel = ChartFactory.createPieChart("Clasificacin", datasetPixel, true, true, false);
    chartPixel.setBackgroundPaint(Color.ORANGE);
    PiePlot plotPixel = (PiePlot) chartPixel.getPlot();
    //Color de las etiquetas
    plotPixel.setLabelBackgroundPaint(Color.ORANGE);
    //Color de el fondo del grfico
    plotPixel.setBackgroundPaint(Color.WHITE);
    plotPixel.setNoDataMessage("No hay data");

    ChartPanel panelPixel = new ChartPanel(chartPixel);
    final JPanel contentPixel = new JPanel(new BorderLayout());
    contentPixel.add(panelPixel);// ww  w  . jav a  2  s . co m
    //panelPixel.setPreferredSize(new java.awt.Dimension(500, 250));
    panelGraficoPixel.setPreferredSize(new java.awt.Dimension(500, 180));

    this.panelGraficoPixel.setLayout(new BorderLayout());
    this.panelGraficoPixel.add(contentPixel);
    contentPixel.setVisible(true);
    this.panelGraficoPixel.setVisible(true);
}

From source file:de.dekarlab.moneybuilder.view.AnalyticsView.java

/**
 * Create pie chart.//w  w  w  .ja  va  2  s. c o  m
 * 
 * @param dataset
 * @param title
 * @return
 */
protected JFreeChart createPieChart(final PieDataset dataset, final String title) {
    final JFreeChart chart = ChartFactory.createPieChart(title, dataset, true, true, false);
    final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setNoDataMessage(App.getGuiProp("report.nodata.msg"));
    plot.setCircular(true);
    // plot.set
    plot.setLabelGap(0.02);
    plot.setBackgroundPaint(Color.white);
    chart.removeLegend();
    plot.setBackgroundPaint(Color.white);
    Iterator<?> it = dataset.getKeys().iterator();
    int color = 0;
    while (it.hasNext()) {
        plot.setSectionPaint((String) it.next(), COLORS[color]);
        color++;
        if (COLORS.length == color) {
            color = 0;
        }
    }
    plot.setLabelBackgroundPaint(Color.white);
    StandardPieSectionLabelGenerator slbl = new StandardPieSectionLabelGenerator("{0} {2} ({1})",
            new DecimalFormat("#,##0"), new DecimalFormat("0%"));
    plot.setLabelGenerator(slbl);
    plot.setLabelFont(new Font("Helvetica", Font.PLAIN, 14));
    plot.setLabelOutlinePaint(Color.white);
    plot.setLabelShadowPaint(Color.white);
    plot.setShadowPaint(Color.white);
    plot.setIgnoreZeroValues(true);
    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   w  w w  .j  a  v a  2  s. 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:org.pau.assetmanager.viewmodel.MonthlyReportViewModel.java

/**
 * Generates the image of a pie chart that displays the percentage of income
 * of the different books which for a given year are profitable
 * //from w  ww.  java 2  s .  c o  m
 * @return the relative random URL generated
 */
@DependsOn({ "selectedBook", "clientType", "monthlyReportYear" })
public String getIncomePieChartURL() {
    if (bookSelection.getSelectedBook() == null) {
        return "";
    }
    List<Annotation> anotations = getAnnotationsInAscendingDateOrder(Optional.of(monthlyReportYear));
    PieDataset categoryModel = ChartDataModel.incomesPieChartDataset(anotations);
    JFreeChart jfchart = ChartFactory.createPieChart(
            "Beneficios ( ingresos menos gastos, siendo los ingresos mayores a los gastos )", categoryModel,
            true, true, false);
    PiePlot piePlot = ((PiePlot) jfchart.getPlot());
    piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({1} , {2} )",
            NumberFomatter.PERCENTAGE_FORMATTER, NumberFormat.getPercentInstance()));
    piePlot.setBackgroundPaint(Color.white);
    return ResourceImageGenerator.getFunction().apply(jfchart);
}

From source file:org.pau.assetmanager.viewmodel.MonthlyReportViewModel.java

/**
 * Generates the image of a pie chart that displays the percentage of
 * expenses of the different books which for a given year are loosing money
 * (not profitable)// w  ww  .  ja  va  2  s  .  com
 * 
 * @return the relative random URL generated
 */
@DependsOn({ "selectedBook", "clientType", "monthlyReportYear" })
public String getDeficitPieChartURL() {
    if (bookSelection.getSelectedBook() == null) {
        return "";
    }
    List<Annotation> anotations = getAnnotationsInAscendingDateOrder(Optional.of(monthlyReportYear));
    PieDataset categoryModel = ChartDataModel.deficitsPieChartDataset(anotations);
    JFreeChart jfchart = ChartFactory.createPieChart(
            "Dficit ( ingresos menos gastos, siendo los gastos mayores a los ingresos )", categoryModel, true,
            true, false);
    PiePlot piePlot = ((PiePlot) jfchart.getPlot());
    piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} (-{1} , {2} )",
            NumberFomatter.PERCENTAGE_FORMATTER, NumberFormat.getPercentInstance()));
    piePlot.setBackgroundPaint(Color.white);
    return ResourceImageGenerator.getFunction().apply(jfchart);
}

From source file:org.pau.assetmanager.viewmodel.MonthlyReportViewModel.java

/**
 * Generates the image of a pie chart that displays the percentage of
 * expenses of the different concept which for a given year are loosing
 * money (not profitable)//from   ww w.  j  a  v  a2 s . com
 * 
 * NOTE: usually, a given concept is only related to either income or
 * expenses but this *not* always the case (for example, in stocks the
 * concept is the company involved and there can be incomes and expenses)
 * 
 * @return the relative random URL generated
 */
@DependsOn({ "selectedBook", "clientType", "monthlyReportYear" })
public String getExpensesPieChartURL() {
    if (bookSelection.getSelectedBook() == null) {
        return "";
    }

    Map<String, Double> expensesDataForBook = AnnotationsBusiness.getExpensesDataForBook(bookSelection,
            monthlyReportYear, clientType);
    PieDataset categoryModel = ChartDataModel.expensesPieChartDataset(expensesDataForBook);
    JFreeChart jfchart = ChartFactory.createPieChart("Gastos (nicamente gastos)", categoryModel, true, true,
            false);
    PiePlot piePlot = ((PiePlot) jfchart.getPlot());
    piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({1} , {2} )",
            NumberFomatter.PERCENTAGE_FORMATTER, NumberFormat.getPercentInstance()));

    piePlot.setBackgroundPaint(Color.white);
    return ResourceImageGenerator.getFunction().apply(jfchart);
}

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 {/*from   w  ww  . j  a v  a  2  s  .  c o  m*/
        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 });
    }
}