use of org.jfree.chart.JFreeChart in project jgnash by ccavanaugh.
the class MonthlyAccountBalanceChartCompare method createPanel.
private JPanel createPanel() {
LocalDate end = DateUtils.getLastDayOfTheMonth(endDateField.getLocalDate());
LocalDate start = end.minusYears(1);
startDateField.setDate(start);
JButton refreshButton = new JButton(rb.getString("Button.Refresh"));
refreshButton.setIcon(IconUtils.getIcon("/jgnash/resource/view-refresh.png"));
subAccountCheckBox = new JCheckBox(rb.getString("Button.IncludeSubAccounts"));
subAccountCheckBox.setSelected(true);
hideLockedAccountCheckBox = new JCheckBox(rb.getString("Button.HideLockedAccount"));
hidePlaceholderAccountCheckBox = new JCheckBox(rb.getString("Button.HidePlaceholderAccount"));
jcb_compare = new JCheckBox(rb.getString("Button.Compare"));
jcb_compare.setSelected(true);
Account a = combo1.getSelectedAccount();
Account a2 = combo2.getSelectedAccount();
JFreeChart chart = createVerticalXYBarChart(a, a2);
final ChartPanel chartPanel = new ChartPanel(chart);
FormLayout layout = new FormLayout("p, 4dlu, p:g", "");
DefaultFormBuilder builder = new DefaultFormBuilder(layout);
FormLayout dLayout = new FormLayout("p, 4dlu, p, 8dlu, p, 4dlu, p, 8dlu, p", "");
DefaultFormBuilder dBuilder = new DefaultFormBuilder(dLayout);
dBuilder.append(rb.getString("Label.StartDate"), startDateField);
dBuilder.append(rb.getString("Label.EndDate"), endDateField);
dBuilder.append(refreshButton);
FormLayout cbLayout = new FormLayout("p, 4dlu, p, 4dlu, p, 4dlu", "");
DefaultFormBuilder cbBuilder = new DefaultFormBuilder(cbLayout);
cbBuilder.append(subAccountCheckBox);
cbBuilder.append(hideLockedAccountCheckBox);
cbBuilder.append(hidePlaceholderAccountCheckBox);
builder.append(rb.getString("Label.Account"), combo1);
builder.nextLine();
builder.append(rb.getString("Label.Compare"), combo2);
builder.nextLine();
builder.append(jcb_compare);
builder.append(cbBuilder.getPanel());
builder.nextLine();
builder.appendRelatedComponentsGapRow();
builder.nextLine();
builder.append(dBuilder.getPanel(), 3);
builder.nextLine();
builder.appendUnrelatedComponentsGapRow();
builder.nextLine();
builder.appendRow(RowSpec.decode("fill:p:g"));
builder.append(chartPanel, 3);
final JPanel panel = builder.getPanel();
ActionListener listener = e -> {
try {
if (e.getSource() == jcb_compare) {
combo2.setEnabled(jcb_compare.isSelected());
}
Account account = combo1.getSelectedAccount();
if (account == null) {
return;
}
Account account2 = combo2.getSelectedAccount();
if (jcb_compare.isSelected() && account2 == null) {
return;
}
updateSubAccountBox();
chartPanel.setChart(createVerticalXYBarChart(account, account2));
panel.validate();
} catch (final Exception ex) {
Logger.getLogger(MonthlyAccountBalanceChartCompare.class.getName()).log(Level.SEVERE, ex.getLocalizedMessage(), ex);
}
};
combo1.addActionListener(listener);
combo2.addActionListener(listener);
jcb_compare.addActionListener(listener);
subAccountCheckBox.addActionListener(listener);
hideLockedAccountCheckBox.addActionListener(e -> {
combo1.setHideLocked(hideLockedAccountCheckBox.isSelected());
combo2.setHideLocked(hideLockedAccountCheckBox.isSelected());
try {
Account account = combo1.getSelectedAccount();
if (account == null) {
return;
}
Account account2 = combo2.getSelectedAccount();
if (jcb_compare.isSelected() && account2 == null) {
return;
}
updateSubAccountBox();
chartPanel.setChart(createVerticalXYBarChart(account, account2));
panel.validate();
} catch (final Exception ex) {
Logger.getLogger(MonthlyAccountBalanceChartCompare.class.getName()).log(Level.SEVERE, ex.getLocalizedMessage(), ex);
}
});
hidePlaceholderAccountCheckBox.addActionListener(e -> {
combo1.setHidePlaceholder(hidePlaceholderAccountCheckBox.isSelected());
combo2.setHidePlaceholder(hidePlaceholderAccountCheckBox.isSelected());
try {
Account account = combo1.getSelectedAccount();
if (account == null) {
return;
}
Account account2 = combo2.getSelectedAccount();
if (jcb_compare.isSelected() && account2 == null) {
return;
}
updateSubAccountBox();
chartPanel.setChart(createVerticalXYBarChart(account, account2));
panel.validate();
} catch (final Exception ex) {
Logger.getLogger(MonthlyAccountBalanceChartCompare.class.getName()).log(Level.SEVERE, ex.getLocalizedMessage(), ex);
}
});
refreshButton.addActionListener(listener);
updateSubAccountBox();
return panel;
}
use of org.jfree.chart.JFreeChart 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.JFreeChart 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.JFreeChart in project jgnash by ccavanaugh.
the class IncomeExpensePieChart method createPanel.
private JPanel createPanel() {
EnumSet<AccountType> set = EnumSet.of(AccountType.INCOME, AccountType.EXPENSE);
JButton refreshButton = new JButton(rb.getString("Button.Refresh"));
startField = new DatePanel();
endField = new DatePanel();
showEmptyCheck = new JCheckBox(rb.getString("Label.ShowEmptyAccounts"));
showPercentCheck = new JCheckBox(rb.getString("Button.ShowPercentValues"));
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
combo = AccountListComboBox.getParentTypeInstance(engine.getRootAccount(), set);
final LocalDate dStart = DateUtils.getFirstDayOfTheMonth(LocalDate.now()).minusYears(1);
long start = pref.getLong(START_DATE, DateUtils.asEpochMilli(dStart));
startField.setDate(DateUtils.asLocalDate(start));
currentAccount = combo.getSelectedAccount();
JFreeChart chart = createPieChart(currentAccount);
chartPanel = new ChartPanel(chart, true, true, true, false, true);
// (chart, properties, save, print, zoom, tooltips)
FormLayout layout = new FormLayout("p, 4dlu, 70dlu, 8dlu, p, 4dlu, 70dlu, 8dlu, p, 4dlu:g, left:p", "f:d, 3dlu, f:d, 6dlu, f:p:g");
DefaultFormBuilder builder = new DefaultFormBuilder(layout);
layout.setRowGroups(new int[][] { { 1, 3 } });
builder.append(combo, 9);
builder.append(showEmptyCheck);
builder.nextLine();
builder.nextLine();
builder.append(rb.getString("Label.StartDate"), startField);
builder.append(rb.getString("Label.EndDate"), endField);
builder.append(refreshButton);
builder.append(showPercentCheck);
builder.nextLine();
builder.nextLine();
builder.append(chartPanel, 11);
JPanel panel = builder.getPanel();
combo.addActionListener(e -> {
setCurrentAccount(combo.getSelectedAccount());
pref.putLong(START_DATE, DateUtils.asEpochMilli(startField.getLocalDate()));
});
refreshButton.addActionListener(e -> {
setCurrentAccount(currentAccount);
pref.putLong(START_DATE, DateUtils.asEpochMilli(startField.getLocalDate()));
});
showEmptyCheck.addActionListener(e -> setCurrentAccount(currentAccount));
showPercentCheck.addActionListener(e -> ((PiePlot) chartPanel.getChart().getPlot()).setLabelGenerator(showPercentCheck.isSelected() ? percentLabels : defaultLabels));
ChartMouseListener mouseListener = new ChartMouseListener() {
@Override
public void chartMouseClicked(final ChartMouseEvent event) {
MouseEvent me = event.getTrigger();
if (me.getID() == MouseEvent.MOUSE_CLICKED && me.getClickCount() == 1) {
try {
ChartEntity entity = event.getEntity();
// expand sections if interesting, back out if in nothing
if (entity instanceof PieSectionEntity) {
Account a = (Account) ((PieSectionEntity) entity).getSectionKey();
if (a.getChildCount() > 0) {
setCurrentAccount(a);
}
} else if (entity == null) {
Account parent = currentAccount;
if (parent == null) {
return;
}
parent = parent.getParent();
if (parent == null || parent instanceof RootAccount) {
return;
}
setCurrentAccount(parent);
}
} catch (final Exception e) {
Logger.getLogger(IncomeExpensePieChart.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
}
}
}
@Override
public void chartMouseMoved(ChartMouseEvent event) {
setChartCursor(chartPanel, event.getEntity(), event.getTrigger().getPoint());
}
};
chartPanel.addChartMouseListener(mouseListener);
return panel;
}
use of org.jfree.chart.JFreeChart in project jgnash by ccavanaugh.
the class RunningAccountBalanceChart method createVerticalXYBarChart.
private JFreeChart createVerticalXYBarChart(Account a) {
DateFormat df = new SimpleDateFormat("MM/yy");
TimeSeriesCollection data = createTimeSeriesCollection(a);
DateAxis dateAxis = new DateAxis(rb.getString("Column.Date"));
dateAxis.setTickUnit(new DateTickUnit(DateTickUnitType.MONTH, 1, df));
dateAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
LocalDate start = DateUtils.getFirstDayOfTheMonth(startDateField.getLocalDate());
LocalDate end = DateUtils.getLastDayOfTheMonth(endDateField.getLocalDate());
dateAxis.setRange(DateUtils.asDate(start), DateUtils.asDate(end));
NumberAxis valueAxis = new NumberAxis(rb.getString("Column.Balance"));
StandardXYToolTipGenerator tooltipGenerator = new StandardXYToolTipGenerator("{1}, {2}", df, NumberFormat.getNumberInstance());
XYBarRenderer renderer = new XYBarRenderer(0.2);
renderer.setBaseToolTipGenerator(tooltipGenerator);
XYPlot plot = new XYPlot(data, dateAxis, valueAxis, renderer);
String title = rb.getString("Title.EndMonthBalance") + " - " + a.getPathName();
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
chart.setBackgroundPaint(null);
return chart;
}
Aggregations