use of org.jfree.chart.plot.PiePlot 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.plot.PiePlot 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.plot.PiePlot in project bamboobsc by billchen198318.
the class CommonPieChartAction method fillChart.
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));
}
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)));
}
use of org.jfree.chart.plot.PiePlot in project processdash by dtuma.
the class PieChart method createChart.
/** Create a line chart. */
@Override
public JFreeChart createChart() {
CategoryDataset catData = data.catDataSource();
PieDataset pieData = null;
if (catData.getColumnCount() == 1)
pieData = DatasetUtilities.createPieDatasetForColumn(catData, 0);
else
pieData = DatasetUtilities.createPieDatasetForRow(catData, 0);
JFreeChart chart = null;
if (get3DSetting()) {
chart = ChartFactory.createPieChart3D(null, pieData, true, true, false);
chart.getPlot().setForegroundAlpha(ALPHA);
} else {
chart = ChartFactory.createPieChart(null, pieData, true, true, false);
}
PiePlot plot = (PiePlot) chart.getPlot();
if (parameters.get("skipItemLabels") != null || parameters.get("skipWedgeLabels") != null)
plot.setLabelGenerator(null);
else if (parameters.get("wedgeLabelFontSize") != null)
try {
float fontSize = Float.parseFloat((String) parameters.get("wedgeLabelFontSize"));
plot.setLabelFont(plot.getLabelFont().deriveFont(fontSize));
} catch (Exception lfe) {
}
if (parameters.get("ellipse") != null)
plot.setCircular(true);
else
plot.setCircular(false);
Object colorScheme = parameters.get("colorScheme");
if ("byPhase".equals(colorScheme))
maybeConfigurePhaseColors(plot, pieData);
else if ("consistent".equals(colorScheme))
// since 2.0.9
configureConsistentColors(plot, pieData);
else if (parameters.containsKey("c1"))
configureIndividualColors(plot, pieData);
String interiorGap = (String) parameters.get("interiorGap");
if (interiorGap != null)
try {
plot.setInteriorGap(Integer.parseInt(interiorGap) / 100.0);
} catch (NumberFormatException e) {
}
String interiorSpacing = (String) parameters.get("interiorSpacing");
if (interiorSpacing != null)
try {
plot.setInteriorGap(Integer.parseInt(interiorSpacing) / 200.0);
} catch (NumberFormatException e) {
}
if (!parameters.containsKey("showZeroValues")) {
plot.setIgnoreZeroValues(true);
plot.setIgnoreNullValues(true);
}
return chart;
}
use of org.jfree.chart.plot.PiePlot 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());
}
}
}
}
}
Aggregations