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;
}
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 >
* 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);
}
Aggregations