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

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

Introduction

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

Prototype

public void setForegroundAlpha(float alpha) 

Source Link

Document

Sets the alpha-transparency for the plot and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:utils.Graphs.java

public static File generate(File baseFolder, String titles[], int[] values, Color backgroundColor) {
    DefaultPieDataset dataset = new DefaultPieDataset();

    // add our data values
    int i = -1;/*from   w w w  .  j  av  a  2  s . c  o m*/
    for (String title : titles) {
        i++;
        dataset.setValue(title, values[i]);
    }

    final JFreeChart chart =
            //                ChartFactory.createPieChart("", dataset, true, true, false);

            ChartFactory.createPieChart("", // chart title
                    dataset, // data
                    true, // include legend
                    true, false);

    PiePlot plot = (PiePlot) chart.getPlot();
    //PiePlot3D plot = (PiePlot3D) chart.getPlot();
    //plot.setStartAngle(290);
    plot.setStartAngle(45);
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.5f);

    //        final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(backgroundColor);

    //        plot.setLegendLabelGenerator(
    //        new StandardPieSectionLabelGenerator("{0} {2}"));

    chart.setBorderVisible(false);
    chart.getPlot().setOutlineVisible(false);
    chart.getLegend().setFrame(BlockBorder.NONE);

    // get the same background
    chart.setBackgroundPaint(backgroundColor);
    chart.getLegend().setBackgroundPaint(backgroundColor);

    // hide the shadow effects
    plot.setShadowXOffset(0);
    plot.setShadowYOffset(0);

    //chart.getLegend().setVisible(false);

    plot.setCircular(true);
    //plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {2}", NumberFormat.getNumberInstance(), NumberFormat
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{2}", NumberFormat.getNumberInstance(),
            NumberFormat.getPercentInstance()));
    plot.setNoDataMessage("No data found.");

    Color greenColor = new Color(0x8FBC0C);
    Color redColor = new Color(0xFF0000);
    //Color redColor = new Color(0xDA6022);

    plot.setSectionPaint(0, greenColor);
    plot.setSectionPaint(1, redColor);
    plot.setSectionOutlinesVisible(true);

    final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
    final File file = new File(baseFolder, "chart.png");
    try {
        ChartUtilities.saveChartAsPNG(file, chart, 200, 160, info);
    } catch (IOException ex) {
        Logger.getLogger(Graphs.class.getName()).log(Level.SEVERE, null, ex);
    }
    //        
    ////        final ChartPanel chartPanel = new ChartPanel(chart, true);
    //       final ChartPanel chartPanel = new ChartPanel(chart, true);
    //        chartPanel.setMinimumDrawWidth(0);
    //        chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE);
    //        chartPanel.setMinimumDrawHeight(0);
    //        chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE);
    //        JDialog dialog = new JDialog();
    //        dialog.add(chartPanel);
    //        dialog.setLayout(new GridLayout(1, 1));
    //        dialog.setSize(400, 200);
    //        dialog.setVisible(true);

    return file;
}

From source file:fr.gouv.diplomatie.applitutoriel.utility.Graphique.java

/**
 * Creer camember3 d.//from w  w  w. j a  va  2 s  .c  om
 *
 * @param title
 *            the title
 * @param dataset
 *            the dataset
 * @param legend
 *            the legend
 * @param tooltips
 *            the tooltips
 * @param urls
 *            the urls
 * @return the j free chart
 * @throws FontFormatException
 *             the font format exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public static JFreeChart creerCamember3D(final String title, final DefaultPieDataset dataset,
        final boolean legend, final boolean tooltips, final boolean urls)
        throws FontFormatException, IOException {

    dataset.sortByValues(SortOrder.DESCENDING);
    final JFreeChart jfreeChart = ChartFactory.createPieChart3D(title, dataset, legend, tooltips, urls);

    jfreeChart.setBackgroundPaint(Color.white);
    jfreeChart.setBorderVisible(true);
    jfreeChart.getLegend().setPosition(RectangleEdge.LEFT);
    final GraphicsEnvironment graph = GraphicsEnvironment.getLocalGraphicsEnvironment();
    final InputStream inputStream = Thread.currentThread().getContextClassLoader()
            .getResourceAsStream("hornet/framework/font/LiberationSans-Bold.ttf");
    final Font font = Font.createFont(Font.TRUETYPE_FONT, inputStream);
    graph.registerFont(font);
    jfreeChart.getLegend().setItemFont(new Font("Liberation Sans", Font.BOLD, 11));
    jfreeChart.getLegend().setHeight(400);
    jfreeChart.getLegend().setBorder(0, 0, 0, 0);
    jfreeChart.setTitle(new TextTitle(title, new Font("Liberation Sans", Font.BOLD, 16)));
    final PiePlot piePlot = (PiePlot) jfreeChart.getPlot();

    final int nbData = dataset.getItemCount();
    int cptColor = 0;
    for (int x = 0; x < nbData; x++) {
        if (cptColor >= listColor.size()) {
            cptColor = 0;
        }
        piePlot.setSectionPaint(dataset.getKey(x), listColor.get(cptColor));

        cptColor++;

    }

    piePlot.setForegroundAlpha(0.5f);
    piePlot.setLabelFont(new Font("Liberation Sans", Font.BOLD, 12));
    piePlot.setLabelOutlineStroke(null);
    piePlot.setLabelLinkStroke(new BasicStroke(0.4f));
    piePlot.setLabelBackgroundPaint(Color.WHITE);
    piePlot.setLabelLinkStyle(PieLabelLinkStyle.STANDARD);
    piePlot.setBackgroundAlpha(0);
    piePlot.setOutlineVisible(false);
    piePlot.setForegroundAlpha(1); // transparence
    piePlot.setInteriorGap(0); // le camembert occupe plus de place
    piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator("{1}"));
    piePlot.setStartAngle(70);
    piePlot.setCircular(true); // force pour avoir un cercle et pas un oval
    piePlot.setMaximumLabelWidth(0.20);
    piePlot.setBaseSectionOutlinePaint(Color.BLACK); // bordure du camembert

    return jfreeChart;

}

From source file:metier.Freechart.java

public void stats() {
    List<Produit> produits = ProduitDAO.getInstance().readAll();

    DefaultPieDataset pieDataset = new DefaultPieDataset();
    for (Produit pr : produits) {
        pieDataset.setValue(pr.getNom(), new Integer(pr.getQuantiteInitial() - pr.getQuantiteDisponible()));

    }/*w  w  w . ja v a2  s.c o m*/
    JFreeChart chart = ChartFactory.createPieChart("Pie Chart", pieDataset, true, true, true);
    //.createPieChart(PieChart, pieDataset, true, true, true);
    PiePlot P = (PiePlot) chart.getPlot();
    P.setForegroundAlpha(TOP_ALIGNMENT);
    ChartFrame frame = new ChartFrame("Pie Chart", chart);
    frame.setVisible(true);
    frame.setSize(450, 500);

}

From source file:jmemorize.gui.swing.panels.SessionChartPanel.java

private JFreeChart createChart(String title, SessionSummary summary) {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue(Localization.get(LC.LEARNED), (int) summary.getPassed());
    dataset.setValue(Localization.get(LC.FAILED), (int) summary.getFailed());
    dataset.setValue(Localization.get(LC.SKIPPED), (int) summary.getSkipped());
    dataset.setValue(Localization.get(LC.RELEARNED), (int) summary.getRelearned());

    JFreeChart chart = ChartFactory.createPieChart3D(title, dataset, true, true, false);

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setForegroundAlpha(0.5f);
    plot.setIgnoreZeroValues(true);//from www  . ja va2s  .c  o  m

    plot.setLabelFont(plot.getLabelFont().deriveFont(11f));
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{1} ({2})"));

    plot.setSectionPaint(Localization.get(LC.LEARNED), ColorConstants.LEARNED_CARDS);
    plot.setSectionPaint(Localization.get(LC.FAILED), ColorConstants.EXPIRED_CARDS);
    plot.setSectionPaint(Localization.get(LC.SKIPPED), ColorConstants.UNLEARNED_CARDS);
    plot.setSectionPaint(Localization.get(LC.RELEARNED), ColorConstants.RELEARNED_CARDS);

    return chart;
}

From source file:com.insa.tp3g1.esbsimulator.view.PieChart.java

/** * Creates a chart */

private JFreeChart createChart(PieDataset dataset, String title) {

    JFreeChart chart = ChartFactory.createPieChart(title, // chart title
            dataset, // data
            true, // include legend
            true, false);//w w  w  . j a  v  a 2s .  co m

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setStartAngle(290);
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.5f);
    return chart;

}

From source file:ca.sqlpower.wabit.swingui.chart.effect.PieChartAnimator.java

@Override
protected void doFrame(int frame, double pct) {
    JFreeChart pieChart = mpplot.getPieChart();
    PiePlot plot = (PiePlot) pieChart.getPlot();

    plot.setStartAngle(spinInterpolator.value(initialAngle, finalAngle, pct));
    plot.setForegroundAlpha((float) alphaInterpolator.value(0.0, 1.0, pct));

    // need to trigger a repaint, because the pie plot is just a stamper
    mpplot.datasetChanged(new DatasetChangeEvent(pieChart, mpplot.getDataset()));
}

From source file:gavisualizer.PieChart.java

@Override
public void generate() {
    // Creates Pie Chart from variables
    JFreeChart chart = ChartFactory.createPieChart(_title, // chart title
            _dataset, // data
            false, // include legend
            false, false);//  w w  w . j  av a 2 s  .  co  m

    // Set Plot canvas color and direction
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.5f);
    plot.setBackgroundPaint(Color.WHITE);

    /*
    *  Use these to edit the decimal percentage: 
    *       NumberFormat nf = NumberFormat.getPercentInstance();
    *       nf.setRoundingMode(RoundingMode.);
    *       nf.setMinimumFractionDigits(2);
    *       plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {2}", NumberFormat.getNumberInstance(), nf));
    *  
    *  And remove line 63
    */

    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {2}"));
    plot.setOutlinePaint(Color.white);

    _chart = chart;
}

From source file:gui.images.ClassifierResultPanel.java

/**
 * Sets the new results for display.//from   w  w  w.j  av a  2s  . com
 *
 * @param prediction Float array corresponding to the classifier prediction.
 * @param classifierName String that is the classifier name.
 * @param classColors Color array representing the class color.
 * @param classNames String array representing the class names.
 */
public void setResults(float[] prediction, String classifierName, Color[] classColors, String[] classNames) {
    int numClasses = classNames.length;
    DefaultPieDataset pieData = new DefaultPieDataset();
    for (int cIndex = 0; cIndex < numClasses; cIndex++) {
        pieData.setValue(classNames[cIndex], prediction[cIndex]);
    }
    JFreeChart chart = ChartFactory.createPieChart3D(classifierName + " prediction", pieData, true, true,
            false);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.5f);
    PieRenderer prend = new PieRenderer(classColors);
    prend.setColor(plot, pieData);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(140, 140));
    resultChartPanel.removeAll();
    resultChartPanel.add(chartPanel);
    resultChartPanel.revalidate();
    resultChartPanel.repaint();
}

From source file:name.martingeisse.reporting.definition.keycount.UnboundChartBlock.java

@Override
public ChartBlock bindToData(final DataSources dataSources) {

    // generate the dataset from the query
    DefaultPieDataset dataset = new DefaultPieDataset();
    IKeyCountResultSet resultSet = query.bindToData(dataSources);
    while (resultSet.next()) {
        KeyCountEntry entry = resultSet.get();
        dataset.setValue(entry.getKey(), entry.getCount());
    }//from  w ww  .  ja v a  2s  .c o  m
    resultSet.close();

    // generate the chart
    JFreeChart chart = ChartFactory.createPieChart("My Title", dataset, true, true, false);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setStartAngle(290);
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.8f);
    return new ChartBlock(chart);

}

From source file:com.netsteadfast.greenstep.action.CommonPieChartAction.java

private void fillChart(String title, List<String> names, List<String> colors, List<Float> values)
        throws Exception {
    DefaultPieDataset data = new DefaultPieDataset();
    for (int ix = 0; ix < names.size(); ix++) {
        data.setValue(names.get(ix), values.get(ix));
    }//from  ww  w  .jav  a  2s. c o  m
    this.chart = ChartFactory.createPieChart3D(title, data, true, true, false);
    LegendTitle legend = this.chart.getLegend();
    legend.setItemFont(new Font("", Font.TRUETYPE_FONT, 9));
    PiePlot plot = (PiePlot) this.chart.getPlot();
    plot.setCircular(true);
    plot.setBackgroundAlpha(0.9f);
    plot.setForegroundAlpha(0.5f);
    plot.setLabelFont(new Font("", Font.TRUETYPE_FONT, 9));
    this.setPlotColor(plot, names, colors);
    this.chart.setTitle(new TextTitle(title, new Font("", Font.TRUETYPE_FONT, 9)));
}