use of org.jfree.chart.labels.StandardPieSectionLabelGenerator in project jgnash by ccavanaugh.
the class PayeePieChart method createPieChart.
private JFreeChart createPieChart(Account a, PieDataset[] data, int index) {
PiePlot plot = new PiePlot(data[index]);
// rebuilt each time because they're based on the account's commodity
NumberFormat valueFormat = CommodityFormat.getFullNumberFormat(a.getCurrencyNode());
NumberFormat percentFormat = new DecimalFormat("0.0#%");
defaultLabels = new StandardPieSectionLabelGenerator("{0} = {1}", valueFormat, percentFormat);
percentLabels = new StandardPieSectionLabelGenerator("{0} = {1}\n{2}", valueFormat, percentFormat);
plot.setLabelGenerator(showPercentCheck.isSelected() ? percentLabels : defaultLabels);
plot.setLabelGap(.02);
plot.setInteriorGap(.1);
BigDecimal thisTotal = BigDecimal.ZERO;
for (int i = 0; i < data[index].getItemCount(); i++) {
thisTotal = thisTotal.add((BigDecimal) (data[index].getValue(i)));
}
BigDecimal acTotal = a.getTreeBalance(startField.getLocalDate(), endField.getLocalDate()).abs();
String title = "";
String subtitle = "";
// pick an appropriate title(s)
if (index == CREDIT) {
title = a.getPathName();
subtitle = rb.getString("Column.Credit") + " : " + valueFormat.format(thisTotal);
} else if (index == DEBIT) {
title = rb.getString("Column.Balance") + " : " + valueFormat.format(acTotal);
subtitle = rb.getString("Column.Debit") + " : " + valueFormat.format(thisTotal);
}
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
chart.addSubtitle(new TextTitle(subtitle));
chart.setBackgroundPaint(null);
return chart;
}
use of org.jfree.chart.labels.StandardPieSectionLabelGenerator in project jgnash by ccavanaugh.
the class IncomeExpensePieChart method createPieChart.
private JFreeChart createPieChart(final Account a) {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
Objects.requireNonNull(a);
PieDataset data = createPieDataSet(a);
PiePlot plot = new PiePlot(data);
// rebuilt each time because they're based on the account's commodity
CurrencyNode defaultCurrency = engine.getDefaultCurrency();
NumberFormat valueFormat = CommodityFormat.getFullNumberFormat(a.getCurrencyNode());
NumberFormat percentFormat = new DecimalFormat("0.0#%");
defaultLabels = new StandardPieSectionLabelGenerator("{0} = {1}", valueFormat, percentFormat);
percentLabels = new StandardPieSectionLabelGenerator("{0} = {1}\n{2}", valueFormat, percentFormat);
plot.setLabelGenerator(showPercentCheck.isSelected() ? percentLabels : defaultLabels);
plot.setLabelGap(.02);
plot.setInteriorGap(.1);
// own transactions, not just child accounts), separate it from children.
if (data.getIndex(a) != -1) {
plot.setExplodePercent(a, .10);
}
String title;
// pick an appropriate title
if (a.getAccountType() == AccountType.EXPENSE) {
title = rb.getString("Title.PercentExpense");
} else if (a.getAccountType() == AccountType.INCOME) {
title = rb.getString("Title.PercentIncome");
} else {
title = rb.getString("Title.PercentDist");
}
title = title + " - " + a.getPathName();
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
BigDecimal total = a.getTreeBalance(startField.getLocalDate(), endField.getLocalDate()).abs();
String subtitle = valueFormat.format(total);
if (!defaultCurrency.equals(a.getCurrencyNode())) {
BigDecimal totalDefaultCurrency = total.multiply(a.getCurrencyNode().getExchangeRate(defaultCurrency));
NumberFormat defaultValueFormat = CommodityFormat.getFullNumberFormat(defaultCurrency);
subtitle += " - " + defaultValueFormat.format(totalDefaultCurrency);
}
chart.addSubtitle(new TextTitle(subtitle));
chart.setBackgroundPaint(null);
return chart;
}
use of org.jfree.chart.labels.StandardPieSectionLabelGenerator in project dhis2-core by dhis2.
the class DefaultChartService method getMultiplePieChart.
private JFreeChart getMultiplePieChart(BaseChart chart, CategoryDataset[] dataSets) {
JFreeChart multiplePieChart = ChartFactory.createMultiplePieChart(chart.getName(), dataSets[0], TableOrder.BY_ROW, !chart.isHideLegend(), false, false);
setBasicConfig(multiplePieChart, chart);
if (multiplePieChart.getLegend() != null) {
multiplePieChart.getLegend().setItemFont(SUB_TITLE_FONT);
}
MultiplePiePlot multiplePiePlot = (MultiplePiePlot) multiplePieChart.getPlot();
JFreeChart pieChart = multiplePiePlot.getPieChart();
pieChart.setBackgroundPaint(COLOR_TRANSPARENT);
pieChart.getTitle().setFont(SUB_TITLE_FONT);
PiePlot piePlot = (PiePlot) pieChart.getPlot();
piePlot.setBackgroundPaint(COLOR_TRANSPARENT);
piePlot.setOutlinePaint(COLOR_TRANSPARENT);
piePlot.setLabelFont(LABEL_FONT);
piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator("{2}"));
piePlot.setSimpleLabels(true);
piePlot.setIgnoreZeroValues(true);
piePlot.setIgnoreNullValues(true);
piePlot.setShadowXOffset(0d);
piePlot.setShadowYOffset(0d);
for (int i = 0; i < dataSets[0].getColumnCount(); i++) {
piePlot.setSectionPaint(dataSets[0].getColumnKey(i), COLORS[(i % COLORS.length)]);
}
return multiplePieChart;
}
use of org.jfree.chart.labels.StandardPieSectionLabelGenerator in project pentaho-platform by pentaho.
the class JFreeChartEngine method updatePlot.
private static void updatePlot(final Plot plot, final ChartDefinition chartDefinition) {
plot.setBackgroundPaint(chartDefinition.getPlotBackgroundPaint());
plot.setBackgroundImage(chartDefinition.getPlotBackgroundImage());
plot.setNoDataMessage(chartDefinition.getNoDataMessage());
// create a custom palette if it was defined
if (chartDefinition.getPaintSequence() != null) {
DefaultDrawingSupplier drawingSupplier = new DefaultDrawingSupplier(chartDefinition.getPaintSequence(), DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE);
plot.setDrawingSupplier(drawingSupplier);
}
// TODO define outline stroke
plot.setOutlineStroke(null);
if (plot instanceof CategoryPlot) {
CategoryPlot categoryPlot = (CategoryPlot) plot;
CategoryDatasetChartDefinition categoryDatasetChartDefintion = (CategoryDatasetChartDefinition) chartDefinition;
categoryPlot.setOrientation(categoryDatasetChartDefintion.getOrientation());
CategoryAxis domainAxis = categoryPlot.getDomainAxis();
if (domainAxis != null) {
domainAxis.setLabel(categoryDatasetChartDefintion.getDomainTitle());
domainAxis.setLabelFont(categoryDatasetChartDefintion.getDomainTitleFont());
if (categoryDatasetChartDefintion.getDomainTickFont() != null) {
domainAxis.setTickLabelFont(categoryDatasetChartDefintion.getDomainTickFont());
}
domainAxis.setCategoryLabelPositions(categoryDatasetChartDefintion.getCategoryLabelPositions());
}
NumberAxis numberAxis = (NumberAxis) categoryPlot.getRangeAxis();
if (numberAxis != null) {
numberAxis.setLabel(categoryDatasetChartDefintion.getRangeTitle());
numberAxis.setLabelFont(categoryDatasetChartDefintion.getRangeTitleFont());
if (categoryDatasetChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
numberAxis.setLowerBound(categoryDatasetChartDefintion.getRangeMinimum());
}
if (categoryDatasetChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
numberAxis.setUpperBound(categoryDatasetChartDefintion.getRangeMaximum());
}
if (categoryDatasetChartDefintion.getRangeTickFormat() != null) {
numberAxis.setNumberFormatOverride(categoryDatasetChartDefintion.getRangeTickFormat());
}
if (categoryDatasetChartDefintion.getRangeTickFont() != null) {
numberAxis.setTickLabelFont(categoryDatasetChartDefintion.getRangeTickFont());
}
if (categoryDatasetChartDefintion.getRangeTickUnits() != null) {
numberAxis.setTickUnit(new NumberTickUnit(categoryDatasetChartDefintion.getRangeTickUnits()));
}
}
}
if (plot instanceof PiePlot) {
PiePlot pie = (PiePlot) plot;
PieDatasetChartDefinition pieDefinition = (PieDatasetChartDefinition) chartDefinition;
pie.setInteriorGap(pieDefinition.getInteriorGap());
pie.setStartAngle(pieDefinition.getStartAngle());
pie.setLabelFont(pieDefinition.getLabelFont());
if (pieDefinition.getLabelPaint() != null) {
pie.setLabelPaint(pieDefinition.getLabelPaint());
}
pie.setLabelBackgroundPaint(pieDefinition.getLabelBackgroundPaint());
if (pieDefinition.isLegendIncluded()) {
// $NON-NLS-1$
StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{0}");
pie.setLegendLabelGenerator(labelGen);
}
if (pieDefinition.getExplodedSlices() != null) {
for (Iterator iter = pieDefinition.getExplodedSlices().iterator(); iter.hasNext(); ) {
pie.setExplodePercent((Comparable) iter.next(), .30);
}
}
pie.setLabelGap(pieDefinition.getLabelGap());
if (!pieDefinition.isDisplayLabels()) {
pie.setLabelGenerator(null);
} else {
if (pieDefinition.isLegendIncluded()) {
// $NON-NLS-1$
StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{1} ({2})");
pie.setLabelGenerator(labelGen);
} else {
// $NON-NLS-1$
StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{0} = {1} ({2})");
pie.setLabelGenerator(labelGen);
}
}
}
if (plot instanceof MultiplePiePlot) {
MultiplePiePlot pies = (MultiplePiePlot) plot;
CategoryDatasetChartDefinition categoryDatasetChartDefintion = (CategoryDatasetChartDefinition) chartDefinition;
pies.setDataset(categoryDatasetChartDefintion);
}
if (plot instanceof MeterPlot) {
MeterPlot meter = (MeterPlot) plot;
DialWidgetDefinition widget = (DialWidgetDefinition) chartDefinition;
List intervals = widget.getIntervals();
Iterator intervalIterator = intervals.iterator();
while (intervalIterator.hasNext()) {
MeterInterval interval = (MeterInterval) intervalIterator.next();
meter.addInterval(interval);
}
meter.setNeedlePaint(widget.getNeedlePaint());
meter.setDialShape(widget.getDialShape());
meter.setDialBackgroundPaint(widget.getPlotBackgroundPaint());
meter.setRange(new Range(widget.getMinimum(), widget.getMaximum()));
}
if (plot instanceof XYPlot) {
XYPlot xyPlot = (XYPlot) plot;
if (chartDefinition instanceof XYSeriesCollectionChartDefinition) {
XYSeriesCollectionChartDefinition xySeriesCollectionChartDefintion = (XYSeriesCollectionChartDefinition) chartDefinition;
xyPlot.setOrientation(xySeriesCollectionChartDefintion.getOrientation());
ValueAxis domainAxis = xyPlot.getDomainAxis();
if (domainAxis != null) {
domainAxis.setLabel(xySeriesCollectionChartDefintion.getDomainTitle());
domainAxis.setLabelFont(xySeriesCollectionChartDefintion.getDomainTitleFont());
domainAxis.setVerticalTickLabels(xySeriesCollectionChartDefintion.isDomainVerticalTickLabels());
if (xySeriesCollectionChartDefintion.getDomainTickFormat() != null) {
((NumberAxis) domainAxis).setNumberFormatOverride(xySeriesCollectionChartDefintion.getDomainTickFormat());
}
if (xySeriesCollectionChartDefintion.getDomainTickFont() != null) {
domainAxis.setTickLabelFont(xySeriesCollectionChartDefintion.getDomainTickFont());
}
if (xySeriesCollectionChartDefintion.getDomainMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
domainAxis.setLowerBound(xySeriesCollectionChartDefintion.getDomainMinimum());
}
if (xySeriesCollectionChartDefintion.getDomainMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
domainAxis.setUpperBound(xySeriesCollectionChartDefintion.getDomainMaximum());
}
}
ValueAxis rangeAxis = xyPlot.getRangeAxis();
if (rangeAxis != null) {
rangeAxis.setLabel(xySeriesCollectionChartDefintion.getRangeTitle());
rangeAxis.setLabelFont(xySeriesCollectionChartDefintion.getRangeTitleFont());
if (xySeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
rangeAxis.setLowerBound(xySeriesCollectionChartDefintion.getRangeMinimum());
}
if (xySeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
rangeAxis.setUpperBound(xySeriesCollectionChartDefintion.getRangeMaximum());
}
if (xySeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
rangeAxis.setLowerBound(xySeriesCollectionChartDefintion.getRangeMinimum());
}
if (xySeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
rangeAxis.setUpperBound(xySeriesCollectionChartDefintion.getRangeMaximum());
}
if (xySeriesCollectionChartDefintion.getRangeTickFormat() != null) {
((NumberAxis) rangeAxis).setNumberFormatOverride(xySeriesCollectionChartDefintion.getRangeTickFormat());
}
if (xySeriesCollectionChartDefintion.getRangeTickFont() != null) {
rangeAxis.setTickLabelFont(xySeriesCollectionChartDefintion.getRangeTickFont());
}
}
} else if (chartDefinition instanceof TimeSeriesCollectionChartDefinition) {
TimeSeriesCollectionChartDefinition timeSeriesCollectionChartDefintion = (TimeSeriesCollectionChartDefinition) chartDefinition;
xyPlot.setOrientation(timeSeriesCollectionChartDefintion.getOrientation());
ValueAxis domainAxis = xyPlot.getDomainAxis();
if (domainAxis != null) {
domainAxis.setLabel(timeSeriesCollectionChartDefintion.getDomainTitle());
domainAxis.setLabelFont(timeSeriesCollectionChartDefintion.getDomainTitleFont());
domainAxis.setVerticalTickLabels(timeSeriesCollectionChartDefintion.isDomainVerticalTickLabels());
if (domainAxis instanceof DateAxis) {
DateAxis da = (DateAxis) domainAxis;
if (timeSeriesCollectionChartDefintion.getDateMinimum() != null) {
da.setMinimumDate(timeSeriesCollectionChartDefintion.getDateMinimum());
}
if (timeSeriesCollectionChartDefintion.getDateMaximum() != null) {
da.setMaximumDate(timeSeriesCollectionChartDefintion.getDateMaximum());
}
}
}
ValueAxis rangeAxis = xyPlot.getRangeAxis();
if (rangeAxis != null) {
rangeAxis.setLabel(timeSeriesCollectionChartDefintion.getRangeTitle());
rangeAxis.setLabelFont(timeSeriesCollectionChartDefintion.getRangeTitleFont());
if (timeSeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
rangeAxis.setLowerBound(timeSeriesCollectionChartDefintion.getRangeMinimum());
}
if (timeSeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
rangeAxis.setUpperBound(timeSeriesCollectionChartDefintion.getRangeMaximum());
}
}
} else if (chartDefinition instanceof XYZSeriesCollectionChartDefinition) {
XYZSeriesCollectionChartDefinition xyzSeriesCollectionChartDefintion = (XYZSeriesCollectionChartDefinition) chartDefinition;
xyPlot.setOrientation(xyzSeriesCollectionChartDefintion.getOrientation());
ValueAxis domainAxis = xyPlot.getDomainAxis();
if (domainAxis != null) {
domainAxis.setLabel(xyzSeriesCollectionChartDefintion.getDomainTitle());
domainAxis.setLabelFont(xyzSeriesCollectionChartDefintion.getDomainTitleFont());
domainAxis.setVerticalTickLabels(xyzSeriesCollectionChartDefintion.isDomainVerticalTickLabels());
if (xyzSeriesCollectionChartDefintion.getDomainMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
domainAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getDomainMinimum());
}
if (xyzSeriesCollectionChartDefintion.getDomainMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
domainAxis.setUpperBound(xyzSeriesCollectionChartDefintion.getDomainMaximum());
}
if (xyzSeriesCollectionChartDefintion.getDomainTickFormat() != null) {
((NumberAxis) domainAxis).setNumberFormatOverride(xyzSeriesCollectionChartDefintion.getDomainTickFormat());
}
if (xyzSeriesCollectionChartDefintion.getDomainTickFont() != null) {
domainAxis.setTickLabelFont(xyzSeriesCollectionChartDefintion.getDomainTickFont());
}
}
ValueAxis rangeAxis = xyPlot.getRangeAxis();
if (rangeAxis != null) {
rangeAxis.setLabel(xyzSeriesCollectionChartDefintion.getRangeTitle());
rangeAxis.setLabelFont(xyzSeriesCollectionChartDefintion.getRangeTitleFont());
rangeAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getRangeMinimum());
if (xyzSeriesCollectionChartDefintion.getRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) {
rangeAxis.setLowerBound(xyzSeriesCollectionChartDefintion.getRangeMinimum());
}
if (xyzSeriesCollectionChartDefintion.getRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) {
rangeAxis.setUpperBound(xyzSeriesCollectionChartDefintion.getRangeMaximum());
}
if (xyzSeriesCollectionChartDefintion.getRangeTickFormat() != null) {
((NumberAxis) rangeAxis).setNumberFormatOverride(xyzSeriesCollectionChartDefintion.getRangeTickFormat());
}
if (xyzSeriesCollectionChartDefintion.getRangeTickFont() != null) {
rangeAxis.setTickLabelFont(xyzSeriesCollectionChartDefintion.getRangeTickFont());
}
}
}
}
}
use of org.jfree.chart.labels.StandardPieSectionLabelGenerator in project xwiki-platform by xwiki.
the class PiePlotGenerator method generate.
@Override
public Plot generate(ChartModel model, Map<String, String> parameters) throws PlotGeneratorException {
PieDataset dataset;
try {
dataset = (PieDataset) model.getDataset();
} catch (ClassCastException e) {
throw new PlotGeneratorException("Incompatible dataset for the pie plot.");
}
PiePlot piePlot = new PiePlot(dataset);
// Allow customizing the label to use
String pieLabelFormat = parameters.get(PIE_LABEL_FORMAT_KEY);
if (pieLabelFormat != null) {
piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator(pieLabelFormat, NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance()));
}
return piePlot;
}
Aggregations