My Test chart:
Code: Select all
private final JFreeChart testBarChart2() {
JFreeChart result = null;
result = ChartFactory.createTimeSeriesChart("Bar Chart 2", "X-Title", "Y-Title", getTimeSeriesCollection1(), true, true, false);
//time series chart has a line renderer as default, so change it to a bar renderer:
final XYPlot xyp = result.getXYPlot();
final XYBarRenderer r = new XYBarRenderer();
r.setMargin(0.2); //10 % space between bars
xyp.setRenderer(r);
//x axis label format:
final DateAxis da = (DateAxis) xyp.getDomainAxis();
da.setStandardTickUnits(getTickUnitSource(new Month(), "yyyy", null)); //show x axis dates only in years
//replace axis with PeriodAxis to have only 1 x tick label per year:
PeriodAxis pa = new PeriodAxis("PeriodAxisLabel", new Month(ICUtils.toDate("20040101", "yyyyMMdd")), new Month(ICUtils.toDate("20121231", "yyyyMMdd")));
// pa.setAutoRangeTimePeriodClass(Year.class);
PeriodAxisLabelInfo[] info = new PeriodAxisLabelInfo[1];
info[0] = new PeriodAxisLabelInfo(Year.class, new SimpleDateFormat("yyyy")); //must be Year.class!
pa.setLabelInfo(info);
xyp.setDomainAxis(pa);
//axis font:
pa.setTickLabelFont(new Font("Helvetica", Font.PLAIN, 24)); //no matter what Font (size) I use - always uses same font!
return result;
}//testBarChart2()