use of org.jfree.chart.plot.PiePlot in project Openfire by igniterealtime.
the class GraphEngine method getPieChart.
/**
* Creates a Pie Chart based on map.
*
* @return the Pie Chart generated.
*/
public JFreeChart getPieChart(Map<String, Double> pieValues) {
DefaultPieDataset dataset = new DefaultPieDataset();
for (String key : pieValues.keySet()) {
dataset.setValue(key, pieValues.get(key));
}
JFreeChart chart = ChartFactory.createPieChart3D(// chart title
null, // data
dataset, // include legend
true, true, false);
chart.setBackgroundPaint(Color.white);
chart.setBorderVisible(false);
chart.setBorderPaint(null);
PiePlot plot = (PiePlot) chart.getPlot();
plot.setSectionOutlinesVisible(false);
plot.setLabelFont(new Font("SansSerif", Font.BOLD, 12));
plot.setNoDataMessage("No data available");
plot.setCircular(true);
plot.setLabelGap(0.02);
plot.setOutlinePaint(null);
plot.setLabelLinksVisible(false);
plot.setLabelGenerator(null);
plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}"));
plot.setStartAngle(270);
plot.setDirection(Rotation.ANTICLOCKWISE);
plot.setForegroundAlpha(0.60f);
plot.setInteriorGap(0.33);
return chart;
}
use of org.jfree.chart.plot.PiePlot in project EnrichmentMapApp by BaderLab.
the class ChartUtil method createRadialHeatMapLegend.
public static JFreeChart createRadialHeatMapLegend(List<EMDataSet> dataSets, ChartOptions options) {
// All the slices must have the same size
final DefaultPieDataset pieDataset = new DefaultPieDataset();
for (EMDataSet ds : dataSets) pieDataset.setValue(ds.getName(), 1);
JFreeChart chart = ChartFactory.createPieChart(// chart title
null, // data
pieDataset, // include legend
false, // tooltips
true, // urls
false);
chart.setAntiAlias(true);
chart.setBorderVisible(false);
chart.setBackgroundPaint(UIManager.getColor("Table.background"));
chart.setBackgroundImageAlpha(0.0f);
chart.setPadding(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
final PiePlot plot = (PiePlot) chart.getPlot();
plot.setCircular(true);
plot.setOutlineVisible(false);
plot.setBackgroundPaint(UIManager.getColor("Table.background"));
plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
plot.setShadowPaint(TRANSPARENT_COLOR);
plot.setShadowXOffset(0.0);
plot.setShadowYOffset(0.0);
plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}"));
plot.setLabelFont(UIManager.getFont("Label.font").deriveFont(LookAndFeelUtil.getSmallFontSize()));
plot.setLabelPaint(UIManager.getColor("Label.foreground"));
plot.setLabelBackgroundPaint(TRANSPARENT_COLOR);
plot.setLabelOutlinePaint(TRANSPARENT_COLOR);
plot.setLabelShadowPaint(TRANSPARENT_COLOR);
plot.setToolTipGenerator(new StandardPieToolTipGenerator("{0}"));
ColorScheme colorScheme = options != null ? options.getColorScheme() : null;
List<Color> colors = colorScheme != null ? colorScheme.getColors() : null;
if (// UP, ZERO, DOWN:
colors == null || colors.size() < 3)
colors = Arrays.asList(new Color[] { Color.LIGHT_GRAY, Color.WHITE, Color.DARK_GRAY });
int total = dataSets.size();
int v = total / -2;
for (EMDataSet ds : dataSets) {
plot.setSectionPaint(ds.getName(), ColorUtil.getColor(v, -total, total, colors.get(2), colors.get(1), colors.get(0)));
v++;
}
return chart;
}
use of org.jfree.chart.plot.PiePlot in project EnrichmentMapApp by BaderLab.
the class RadialHeatMapLayer method createChart.
@Override
protected JFreeChart createChart(final PieDataset dataset) {
JFreeChart chart = ChartFactory.createPieChart(// chart title
null, // data
dataset, // include legend
false, // tooltips
false, // urls
false);
chart.setAntiAlias(true);
chart.setBorderVisible(false);
chart.setBackgroundPaint(TRANSPARENT_COLOR);
chart.setBackgroundImageAlpha(0.0f);
chart.setPadding(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
final PiePlot plot = (PiePlot) chart.getPlot();
plot.setCircular(true);
plot.setStartAngle(startAngle);
plot.setDirection(rotation == Rotation.ANTICLOCKWISE ? org.jfree.util.Rotation.ANTICLOCKWISE : org.jfree.util.Rotation.CLOCKWISE);
plot.setOutlineVisible(false);
plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
plot.setInteriorGap(INTERIOR_GAP);
plot.setBackgroundPaint(TRANSPARENT_COLOR);
plot.setBackgroundAlpha(0.0f);
plot.setShadowPaint(TRANSPARENT_COLOR);
plot.setShadowXOffset(0.0);
plot.setShadowYOffset(0.0);
plot.setLabelGenerator(showItemLabels ? new CustomPieSectionLabelGenerator(labels) : null);
plot.setSimpleLabels(true);
plot.setLabelFont(plot.getLabelFont().deriveFont(itemFontSize));
plot.setLabelBackgroundPaint(TRANSPARENT_COLOR);
plot.setLabelOutlinePaint(TRANSPARENT_COLOR);
plot.setLabelShadowPaint(TRANSPARENT_COLOR);
plot.setLabelPaint(labelColor);
final BasicStroke stroke = new BasicStroke(borderWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
Color upperColor = Color.BLUE;
Color zeroColor = Color.WHITE;
Color lowerColor = Color.RED;
Color nanColor = DEFAULT_ITEM_BG_COLOR;
if (range != null && range.size() >= 2 && range.get(0) != null && range.get(1) != null) {
final int colorsSize = colors != null ? colors.size() : 0;
if (colorsSize > 0)
upperColor = colors.get(0);
if (colorsSize > 1)
zeroColor = colors.get(1);
if (colorsSize > 2)
lowerColor = colors.get(2);
if (colorsSize > 3)
nanColor = colors.get(3);
}
final List<?> keys = dataset.getKeys();
final List<Double> values = data.isEmpty() ? null : data.values().iterator().next();
for (int i = 0; i < keys.size(); i++) {
String k = (String) keys.get(i);
Double v = values.size() > i ? values.get(i) : null;
final Color c;
if (v == null)
c = nanColor;
else
c = ColorUtil.getColor(v, range.get(0), range.get(1), lowerColor, zeroColor, upperColor);
plot.setSectionPaint(k, c);
plot.setSectionOutlinePaint(k, borderWidth > 0 ? borderColor : TRANSPARENT_COLOR);
plot.setSectionOutlineStroke(k, stroke);
}
return chart;
}
use of org.jfree.chart.plot.PiePlot 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.plot.PiePlot in project tdq-studio-se by Talend.
the class ChartDecorator method decoratePiePlot.
/**
* DOC qiongli Comment method "decoratePiePlot".
*
* @param chart
*/
private static void decoratePiePlot(JFreeChart chart) {
// $NON-NLS-1$
Font font = new Font("sans-serif", Font.BOLD, BASE_TITLE_LABEL_SIZE);
TextTitle textTitle = chart.getTitle();
// MOD msjian TDQ-5213 2012-5-7: fixed NPE
if (textTitle != null) {
textTitle.setFont(font);
}
setLegendFont(chart);
// TDQ-5213~
PiePlot plot = (PiePlot) chart.getPlot();
// $NON-NLS-1$
font = new Font("Monospaced", Font.PLAIN, 10);
plot.setLabelFont(font);
// $NON-NLS-1$
plot.setNoDataMessage("No data available");
StandardPieSectionLabelGenerator standardPieSectionLabelGenerator = new // $NON-NLS-1$
StandardPieSectionLabelGenerator(// $NON-NLS-1$
("{0}:{2}"), NumberFormat.getNumberInstance(), new DecimalFormat(PERCENT_FORMAT));
plot.setLabelGenerator(standardPieSectionLabelGenerator);
plot.setLabelLinkPaint(Color.GRAY);
plot.setLabelOutlinePaint(Color.WHITE);
plot.setLabelGap(0.02D);
plot.setOutlineVisible(false);
plot.setMaximumLabelWidth(0.2D);
plot.setCircular(false);
// remove the shadow of the pie chart
plot.setShadowXOffset(0);
plot.setShadowYOffset(0);
}
Aggregations