use of org.jfree.data.general.PieDataset 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.data.general.PieDataset in project processdash by dtuma.
the class DiscChart method createDiscChart.
public static JFreeChart createDiscChart(ResultSet data, Map parameters) {
// data.sortBy(1, true);
CategoryDataset catData = data.catDataSource();
PieDataset pieData = null;
if (catData.getColumnCount() == 1)
pieData = DatasetUtilities.createPieDatasetForColumn(catData, 0);
else
pieData = DatasetUtilities.createPieDatasetForRow(catData, 0);
DiscPlot plot = new DiscPlot(pieData);
plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
plot.setDrawingSupplier(DRAWING_SUPPLIER_FACTORY.newDrawingSupplier());
JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
if (parameters.get("skipItemLabels") != null || parameters.get("skipDiscLabels") != null)
plot.setLabelGenerator(null);
else if (parameters.get("discLabelFontSize") != null)
try {
float fontSize = Float.parseFloat((String) parameters.get("discLabelFontSize"));
plot.setLabelFont(plot.getLabelFont().deriveFont(fontSize));
} catch (Exception lfe) {
}
if (parameters.get("ellipse") != null)
((StandardDiscItemDistributor) plot.getDiscDistributor()).setCircular(false);
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) {
}
return chart;
}
use of org.jfree.data.general.PieDataset 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.data.general.PieDataset 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;
}
use of org.jfree.data.general.PieDataset in project cytoscape-impl by cytoscape.
the class RingLayer method createDataset.
// ==[ PRIVATE METHODS ]============================================================================================
@Override
protected PieDataset createDataset() {
datasetList = new ArrayList<PieDataset>();
for (final String category : data.keySet()) {
final List<Double> values = data.get(category);
final PieDataset ds = createPieDataset(values);
if (ds != null)
datasetList.add(ds);
}
if (showItemLabels && itemLabels != null && datasetList.size() == 1) {
final List<?> keys = datasetList.get(0).getKeys();
for (int i = 0; i < keys.size(); i++) {
final String k = (String) keys.get(i);
final String label = itemLabels.size() > i ? itemLabels.get(i) : null;
labels.put(k, label);
}
}
return datasetList.isEmpty() ? null : datasetList.get(0);
}
Aggregations