use of org.jfree.chart.ChartPanel in project processdash by dtuma.
the class ScheduleBalancingDialog method addChartToPanel.
private void addChartToPanel(JPanel panel, int gridY) {
// create a dataset for displaying schedule data
chartData = new ChartData();
updateChart();
// customize a renderer for displaying schedules
XYBarRenderer renderer = new XYBarRenderer();
renderer.setUseYInterval(true);
renderer.setBaseToolTipGenerator(chartData);
renderer.setDrawBarOutline(true);
// use an inverted, unadorned numeric Y-axis
NumberAxis yAxis = new NumberAxis();
yAxis.setInverted(true);
yAxis.setTickLabelsVisible(false);
yAxis.setTickMarksVisible(false);
yAxis.setUpperMargin(0);
// use a Date-based X-axis
DateAxis xAxis = new DateAxis();
// create an XY plot to display the data
XYPlot plot = new XYPlot(chartData, xAxis, yAxis, renderer);
plot.setOrientation(PlotOrientation.VERTICAL);
plot.setRangeGridlinesVisible(false);
plot.setNoDataMessage(TaskScheduleDialog.resources.getString("Chart.No_Data_Message"));
// create a chart and a chart panel
JFreeChart chart = new JFreeChart(plot);
chart.removeLegend();
ChartPanel chartPanel = new ChartPanel(chart, false);
chartPanel.setInitialDelay(50);
chartPanel.setDismissDelay(60000);
chartPanel.setMinimumDrawHeight(40);
chartPanel.setMinimumDrawWidth(40);
chartPanel.setMaximumDrawHeight(3000);
chartPanel.setMaximumDrawWidth(3000);
chartPanel.setPreferredSize(new Dimension(300, gridY * 25));
// add the chart to the dialog content pane
GridBagConstraints c = new GridBagConstraints();
c.gridy = gridY;
c.gridwidth = 4;
c.weightx = 2;
c.weighty = 1;
c.fill = GridBagConstraints.BOTH;
c.insets = new Insets(10, 0, 0, 0);
panel.add(chartPanel, c);
// colors with the schedule rows so they can act as a legend
for (int i = scheduleRows.size(); i-- > 0; ) {
ScheduleTableRow oneRow = scheduleRows.get(i);
oneRow.addColoredIcon(renderer.lookupSeriesPaint(i));
}
}
use of org.jfree.chart.ChartPanel in project jgnash by ccavanaugh.
the class PayeePieChart method createPanel.
private JPanel createPanel() {
JButton refreshButton = new JButton(rb.getString("Button.Refresh"));
JButton addFilterButton = new JButton(rb.getString("Button.AddFilter"));
final JButton saveButton = new JButton(rb.getString("Button.SaveFilters"));
JButton deleteFilterButton = new JButton(rb.getString("Button.DeleteFilter"));
JButton clearPrefButton = new JButton(rb.getString("Button.MasterDelete"));
filterCombo = new JComboBox<>();
startField = new DatePanel();
endField = new DatePanel();
txtAddFilter = new TextField();
filterList = new ArrayList<>();
filtersChanged = false;
useFilters = new JCheckBox(rb.getString("Label.UseFilters"));
useFilters.setSelected(true);
showPercentCheck = new JCheckBox(rb.getString("Button.ShowPercentValues"));
combo = AccountListComboBox.getFullInstance();
final LocalDate dStart = DateUtils.getFirstDayOfTheMonth(LocalDate.now().minusYears(DEBIT));
long start = pref.getLong(START_DATE, DateUtils.asEpochMilli(dStart));
startField.setDate(DateUtils.asLocalDate(start));
currentAccount = combo.getSelectedAccount();
PieDataset[] data = createPieDataSet(currentAccount);
JFreeChart chartCredit = createPieChart(currentAccount, data, CREDIT);
chartPanelCredit = new ChartPanel(chartCredit, true, true, true, false, true);
// (chart, properties, save, print, zoom, tooltips)
JFreeChart chartDebit = createPieChart(currentAccount, data, DEBIT);
chartPanelDebit = new ChartPanel(chartDebit, true, true, true, false, true);
FormLayout layout = new FormLayout("p, $lcgap, 70dlu, 8dlu, p, $lcgap, 70dlu, $ugap, p, $lcgap:g, left:p", "d, $rgap, d, $ugap, f:p:g, $rgap, d");
DefaultFormBuilder builder = new DefaultFormBuilder(layout);
layout.setRowGroups(new int[][] { { DEBIT, 3 } });
// row 1
builder.append(combo, 9);
builder.append(useFilters);
builder.nextLine();
builder.nextLine();
// row 3
builder.append(rb.getString("Label.StartDate"), startField);
builder.append(rb.getString("Label.EndDate"), endField);
builder.append(refreshButton);
builder.append(showPercentCheck);
builder.nextLine();
builder.nextLine();
// row 5
FormLayout subLayout = new FormLayout("180dlu:g, 1dlu, 180dlu:g", "f:180dlu:g");
DefaultFormBuilder subBuilder = new DefaultFormBuilder(subLayout);
subBuilder.append(chartPanelCredit);
subBuilder.append(chartPanelDebit);
builder.append(subBuilder.getPanel(), 11);
builder.nextLine();
builder.nextLine();
// row 7
builder.append(txtAddFilter, 3);
builder.append(addFilterButton, 3);
builder.append(saveButton);
builder.nextLine();
// row
builder.append(filterCombo, 3);
builder.append(deleteFilterButton, 3);
builder.append(clearPrefButton);
builder.nextLine();
JPanel panel = builder.getPanel();
combo.addActionListener(e -> {
Account newAccount = combo.getSelectedAccount();
if (filtersChanged) {
int result = JOptionPane.showConfirmDialog(null, rb.getString("Message.SaveFilters"), "Warning", JOptionPane.YES_NO_OPTION);
if (result == JOptionPane.YES_OPTION) {
saveButton.doClick();
}
}
filtersChanged = false;
String[] list = POUND_DELIMITER_PATTERN.split(pref.get(FILTER_TAG + newAccount.hashCode(), ""));
filterList.clear();
for (String filter : list) {
if (!filter.isEmpty()) {
filterList.add(filter);
}
}
refreshFilters();
setCurrentAccount(newAccount);
pref.putLong(START_DATE, DateUtils.asEpochMilli(startField.getLocalDate()));
});
refreshButton.addActionListener(e -> {
setCurrentAccount(currentAccount);
pref.putLong(START_DATE, DateUtils.asEpochMilli(startField.getLocalDate()));
});
clearPrefButton.addActionListener(e -> {
int result = JOptionPane.showConfirmDialog(null, rb.getString("Message.MasterDelete"), "Warning", JOptionPane.YES_NO_OPTION);
if (result == JOptionPane.YES_OPTION) {
try {
pref.clear();
} catch (Exception ex) {
System.out.println("Exception clearing preferences" + ex);
}
}
});
saveButton.addActionListener(e -> {
final StringBuilder sb = new StringBuilder();
for (String filter : filterList) {
sb.append(filter);
sb.append('#');
}
pref.put(FILTER_TAG + currentAccount.hashCode(), sb.toString());
filtersChanged = false;
});
addFilterButton.addActionListener(e -> {
String newFilter = txtAddFilter.getText();
filterList.remove(newFilter);
if (!newFilter.isEmpty()) {
filterList.add(newFilter);
filtersChanged = true;
txtAddFilter.setText("");
}
refreshFilters();
});
deleteFilterButton.addActionListener(e -> {
if (!filterList.isEmpty()) {
String filter = (String) filterCombo.getSelectedItem();
filterList.remove(filter);
filtersChanged = true;
}
refreshFilters();
});
useFilters.addActionListener(e -> setCurrentAccount(currentAccount));
showPercentCheck.addActionListener(e -> {
((PiePlot) chartPanelCredit.getChart().getPlot()).setLabelGenerator(showPercentCheck.isSelected() ? percentLabels : defaultLabels);
((PiePlot) chartPanelDebit.getChart().getPlot()).setLabelGenerator(showPercentCheck.isSelected() ? percentLabels : defaultLabels);
});
return panel;
}
use of org.jfree.chart.ChartPanel in project jgnash by ccavanaugh.
the class RunningAccountBalanceChart 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"));
JFreeChart chart = createVerticalXYBarChart(combo.getSelectedAccount());
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"), combo);
builder.nextLine();
builder.append(" ");
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 -> {
updateSubAccountBox();
Account a = combo.getSelectedAccount();
if (a == null) {
return;
}
chartPanel.setChart(createVerticalXYBarChart(a));
panel.validate();
};
hideLockedAccountCheckBox.addActionListener(e -> {
combo.setHideLocked(hideLockedAccountCheckBox.isSelected());
updateSubAccountBox();
Account a = combo.getSelectedAccount();
if (a == null) {
return;
}
chartPanel.setChart(createVerticalXYBarChart(a));
panel.validate();
});
hidePlaceholderAccountCheckBox.addActionListener(e -> {
combo.setHidePlaceholder(hidePlaceholderAccountCheckBox.isSelected());
updateSubAccountBox();
Account a = combo.getSelectedAccount();
if (a == null) {
return;
}
chartPanel.setChart(createVerticalXYBarChart(a));
panel.validate();
});
updateSubAccountBox();
combo.addActionListener(listener);
refreshButton.addActionListener(listener);
return panel;
}
use of org.jfree.chart.ChartPanel in project jgnash by ccavanaugh.
the class SecurityHighLowChart method createPanel.
private JPanel createPanel() {
combo = new SecurityComboBox();
// create an empty chart for panel construction
chartPanel = new ChartPanel(new JFreeChart(new XYPlot()));
FormLayout layout = new FormLayout("p, 4dlu:g", "");
DefaultFormBuilder builder = new DefaultFormBuilder(layout);
builder.append(combo);
builder.nextLine();
builder.appendRelatedComponentsGapRow();
builder.nextLine();
builder.appendRow(RowSpec.decode("fill:p:g"));
builder.append(chartPanel, 2);
combo.addActionListener(e -> updateChart());
return builder.getPanel();
}
use of org.jfree.chart.ChartPanel in project gephi by gephi.
the class JFreeChartDialog method initialize.
private void initialize(JFreeChart chart) {
initComponents();
if (chart == null) {
throw new IllegalArgumentException("Chart panel can't be null");
}
this.chartPanel = new ChartPanel(chart, true);
scroll.setViewportView(chartPanel);
adaptChartPanelSizeToScrollSize();
scroll.revalidate();
scroll.repaint();
setVisible(true);
}
Aggregations