Search in sources :

Example 71 with StandardPieSectionLabelGenerator

use of org.jfree.chart.labels.StandardPieSectionLabelGenerator in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class ChartFactory method createRingChart.

/**
 * Creates a ring chart with default settings.
 * <P>
 * The chart object returned by this method uses a {@link RingPlot}
 * instance as the plot.
 *
 * @param title  the chart title ({@code null} permitted).
 * @param dataset  the dataset for the chart ({@code null} permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param locale  the locale ({@code null} not permitted).
 *
 * @return A ring chart.
 */
public static JFreeChart createRingChart(String title, PieDataset dataset, boolean legend, boolean tooltips, Locale locale) {
    RingPlot plot = new RingPlot(dataset);
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator(locale));
    plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
    if (tooltips) {
        plot.setToolTipGenerator(new StandardPieToolTipGenerator(locale));
    }
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    currentTheme.apply(chart);
    return chart;
}
Also used : RingPlot(org.jfree.chart.plot.RingPlot) StandardPieToolTipGenerator(org.jfree.chart.labels.StandardPieToolTipGenerator) RectangleInsets(org.jfree.chart.api.RectangleInsets) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator)

Example 72 with StandardPieSectionLabelGenerator

use of org.jfree.chart.labels.StandardPieSectionLabelGenerator in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class ChartFactory method createPieChart.

/**
 * Creates a pie chart with default settings that compares 2 datasets.
 * The colour of each section will be determined by the move from the value
 * for the same key in {@code previousDataset}. ie if value1 &gt;
 * value2 then the section will be in green (unless
 * {@code greenForIncrease} is {@code false}, in which case it
 * would be {@code red}). Each section can have a shade of red or
 * green as the difference can be tailored between 0% (black) and
 * percentDiffForMaxScale% (bright red/green).
 * <p>
 * For instance if {@code percentDiffForMaxScale} is 10 (10%), a
 * difference of 5% will have a half shade of red/green, a difference of
 * 10% or more will have a maximum shade/brightness of red/green.
 * <P>
 * The chart object returned by this method uses a {@link PiePlot} instance
 * as the plot.
 * <p>
 * Written by <a href="mailto:opensource@objectlab.co.uk">Benoit
 * Xhenseval</a>.
 *
 * @param title  the chart title ({@code null} permitted).
 * @param dataset  the dataset for the chart ({@code null} permitted).
 * @param previousDataset  the dataset for the last run, this will be used
 *                         to compare each key in the dataset
 * @param percentDiffForMaxScale scale goes from bright red/green to black,
 *                               percentDiffForMaxScale indicate the change
 *                               required to reach top scale.
 * @param greenForIncrease  an increase since previousDataset will be
 *                          displayed in green (decrease red) if true.
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param locale  the locale ({@code null} not permitted).
 * @param subTitle displays a subtitle with colour scheme if true
 * @param showDifference  create a new dataset that will show the %
 *                        difference between the two datasets.
 *
 * @return A pie chart.
 */
public static JFreeChart createPieChart(String title, PieDataset dataset, PieDataset previousDataset, int percentDiffForMaxScale, boolean greenForIncrease, boolean legend, boolean tooltips, Locale locale, boolean subTitle, boolean showDifference) {
    PiePlot plot = new PiePlot(dataset);
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator(locale));
    plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
    if (tooltips) {
        plot.setToolTipGenerator(new StandardPieToolTipGenerator(locale));
    }
    List keys = dataset.getKeys();
    DefaultPieDataset series = null;
    if (showDifference) {
        series = new DefaultPieDataset();
    }
    double colorPerPercent = 255.0 / percentDiffForMaxScale;
    for (Iterator it = keys.iterator(); it.hasNext(); ) {
        Comparable key = (Comparable) it.next();
        Number newValue = dataset.getValue(key);
        Number oldValue = previousDataset.getValue(key);
        if (oldValue == null) {
            sectionPaint(greenForIncrease, plot, key, showDifference, series, newValue);
        } else {
            pieChartSectionPaint(percentDiffForMaxScale, greenForIncrease, showDifference, plot, series, colorPerPercent, key, newValue, oldValue);
        }
    }
    return subtitlingPieChart(title, percentDiffForMaxScale, greenForIncrease, legend, subTitle, showDifference, plot, series);
}
Also used : DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) StandardPieToolTipGenerator(org.jfree.chart.labels.StandardPieToolTipGenerator) Iterator(java.util.Iterator) MultiplePiePlot(org.jfree.chart.plot.pie.MultiplePiePlot) PiePlot(org.jfree.chart.plot.pie.PiePlot) RectangleInsets(org.jfree.chart.api.RectangleInsets) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) List(java.util.List)

Aggregations

StandardPieSectionLabelGenerator (org.jfree.chart.labels.StandardPieSectionLabelGenerator)72 PiePlot (org.jfree.chart.plot.PiePlot)47 JFreeChart (org.jfree.chart.JFreeChart)31 DecimalFormat (java.text.DecimalFormat)30 DefaultPieDataset (org.jfree.data.general.DefaultPieDataset)30 StandardPieToolTipGenerator (org.jfree.chart.labels.StandardPieToolTipGenerator)26 PieSectionLabelGenerator (org.jfree.chart.labels.PieSectionLabelGenerator)24 MultiplePiePlot (org.jfree.chart.plot.MultiplePiePlot)21 File (java.io.File)17 IOException (java.io.IOException)17 Connection (java.sql.Connection)16 ResultSet (java.sql.ResultSet)16 SQLException (java.sql.SQLException)16 Statement (java.sql.Statement)16 DateFormat (java.text.DateFormat)16 SimpleDateFormat (java.text.SimpleDateFormat)16 ImageIcon (javax.swing.ImageIcon)16 BlueSeerUtils.currformatDouble (com.blueseer.utl.BlueSeerUtils.currformatDouble)13 RectangleInsets (org.jfree.ui.RectangleInsets)13 Font (java.awt.Font)12