use of org.jfree.chart.axis.NumberAxis in project EnrichmentMapApp by BaderLab.
the class ChartUtil method createHeatStripsLegend.
@SuppressWarnings("serial")
public static JFreeChart createHeatStripsLegend(List<EMDataSet> dataSets, ChartOptions options) {
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
int total = dataSets.size();
int v = total / -2;
for (int i = 0; i < total; i++) {
// Just to make sure there is always a bar for each data set name
if (v == 0.0)
v = 1;
dataset.addValue(v++, options.getData().toString(), dataSets.get(i).getName());
}
final JFreeChart chart = ChartFactory.createBarChart(// chart title
null, // domain axis label
null, // range axis label
null, // data
dataset, PlotOrientation.VERTICAL, // 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 CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setOutlineVisible(false);
plot.setBackgroundPaint(UIManager.getColor("Table.background"));
plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
plot.setDomainGridlinesVisible(false);
plot.setRangeGridlinesVisible(false);
final CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis();
domainAxis.setVisible(true);
domainAxis.setAxisLineVisible(false);
domainAxis.setTickMarksVisible(false);
domainAxis.setTickLabelFont(UIManager.getFont("Label.font").deriveFont(LookAndFeelUtil.getSmallFontSize()));
domainAxis.setLabelPaint(UIManager.getColor("Label.foreground"));
domainAxis.setMaximumCategoryLabelLines(1);
domainAxis.setCategoryMargin(0.0);
if (total > 4) {
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
domainAxis.setMaximumCategoryLabelWidthRatio(0.5f);
} else {
domainAxis.setMaximumCategoryLabelLines(2);
}
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setVisible(false);
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 });
List<Color> itemColors = new ArrayList<>();
for (int i = 0; i < total; i++) {
Number n = dataset.getValue(options.getData().toString(), dataSets.get(i).getName());
itemColors.add(ColorUtil.getColor(n.doubleValue(), -total, total, colors.get(2), colors.get(1), colors.get(0)));
}
final BarRenderer renderer = new BarRenderer() {
@Override
public Paint getItemPaint(int row, int column) {
return column < itemColors.size() ? itemColors.get(column) : Color.LIGHT_GRAY;
}
};
plot.setRenderer(renderer);
renderer.setBarPainter(new StandardBarPainter());
renderer.setDrawBarOutline(true);
renderer.setShadowVisible(false);
renderer.setItemMargin(0.0);
renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator("{1}", NumberFormat.getInstance()));
return chart;
}
use of org.jfree.chart.axis.NumberAxis in project jgnash by ccavanaugh.
the class BudgetSparkline method getSparklineImage.
public static Icon getSparklineImage(final List<BigDecimal> amounts) {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
final boolean[] negate = new boolean[amounts.size()];
for (int i = 0; i < amounts.size(); i++) {
dataset.addValue(amounts.get(i), CATEGORY, i);
negate[i] = amounts.get(i).signum() == -1;
}
CategoryAxis xAxis = new CategoryAxis();
xAxis.setTickLabelsVisible(false);
xAxis.setTickMarksVisible(false);
xAxis.setAxisLineVisible(false);
xAxis.setVisible(false);
NumberAxis yAxis = new NumberAxis();
yAxis.setTickLabelsVisible(false);
yAxis.setTickMarksVisible(false);
yAxis.setAxisLineVisible(false);
yAxis.setNegativeArrowVisible(false);
yAxis.setPositiveArrowVisible(false);
yAxis.setAutoRangeIncludesZero(true);
yAxis.setAutoRange(true);
yAxis.setVisible(false);
BarRenderer renderer = new BarRenderer() {
@Override
public Paint getItemPaint(final int row, final int column) {
return negate[column] ? Color.RED : Color.BLACK;
}
};
renderer.setShadowVisible(false);
renderer.setBarPainter(new StandardBarPainter());
CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
plot.setInsets(INSETS);
plot.setDomainGridlinesVisible(false);
plot.setDomainCrosshairVisible(false);
plot.setRangeGridlinesVisible(false);
plot.setRangeCrosshairVisible(false);
plot.setBackgroundPaint(CLEAR);
JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
chart.setBorderVisible(false);
chart.setBackgroundPaint(CLEAR);
Icon icon = EMPTY_ICON;
try {
byte[] image = ENCODER.encode(chart.createBufferedImage(DEFAULT_WIDTH, DEFAULT_HEIGHT, BufferedImage.BITMASK, null));
icon = new ImageIcon(image);
} catch (IOException ex) {
Logger.getLogger(BudgetSparkline.class.getName()).log(Level.SEVERE, null, ex);
}
return icon;
}
use of org.jfree.chart.axis.NumberAxis in project jgnash by ccavanaugh.
the class MonthlyAccountBalanceChart 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);
// if (a.getTransactionCount() > 0) {
Date start = DateUtils.asDate(DateUtils.getFirstDayOfTheMonth(startDateField.getLocalDate()));
Date end = DateUtils.asDate(DateUtils.getLastDayOfTheMonth(endDateField.getLocalDate()));
dateAxis.setRange(start, 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.AccountBalance") + " - " + a.getPathName();
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
chart.setBackgroundPaint(null);
return chart;
}
use of org.jfree.chart.axis.NumberAxis in project jgnash by ccavanaugh.
the class MonthlyAccountBalanceChartCompare method createVerticalXYBarChart.
private JFreeChart createVerticalXYBarChart(final Account a, final Account a2) {
DateFormat df = new SimpleDateFormat("MM/yy");
TimeSeriesCollection data = createTimeSeriesCollection(a, a2);
DateAxis dateAxis = new DateAxis(rb.getString("Column.Date"));
dateAxis.setTickUnit(new DateTickUnit(DateTickUnitType.MONTH, 1, df));
dateAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
// if (a.getTransactionCount() > 0) {
Date start = DateUtils.asDate(DateUtils.getFirstDayOfTheMonth(startDateField.getLocalDate()));
Date end = DateUtils.asDate(DateUtils.getLastDayOfTheMonth(endDateField.getLocalDate()));
dateAxis.setRange(start, end);
// }
NumberAxis valueAxis = new NumberAxis(rb.getString("Column.Balance") + "-" + a.getCurrencyNode().getSymbol());
StandardXYToolTipGenerator tooltipGenerator = new StandardXYToolTipGenerator("{1}, {2}", df, NumberFormat.getNumberInstance());
ClusteredXYBarRenderer renderer = new ClusteredXYBarRenderer(0.2, false);
renderer.setBaseToolTipGenerator(tooltipGenerator);
XYPlot plot = new XYPlot(data, dateAxis, valueAxis, renderer);
String title;
if (jcb_compare.isSelected()) {
title = a.getPathName() + " vs " + a2.getPathName();
} else {
title = rb.getString("Title.AccountBalance") + " - " + a.getPathName();
}
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
chart.setBackgroundPaint(null);
return chart;
}
use of org.jfree.chart.axis.NumberAxis 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