It appears that the JFreeChart (Javadoc) class contains a Font object. It's sad to see the developers not enabling the modification of the font by default, but anyway here's how I solved this...
class CustomChartFactory extends ChartFactory{
public static JFreeChart createCustomBarChart(String title,
String categoryAxisLabel, String valueAxisLabel,
CategoryDataset dataset, PlotOrientation orientation,
boolean legend, boolean tooltips, boolean urls, Font font) {
ParamChecks.nullNotPermitted(orientation, "orientation");
CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
BarRenderer renderer = new BarRenderer();
if (orientation == PlotOrientation.HORIZONTAL) {
ItemLabelPosition position1 = new ItemLabelPosition(
ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT);
renderer.setBasePositiveItemLabelPosition(position1);
ItemLabelPosition position2 = new ItemLabelPosition(
ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT);
renderer.setBaseNegativeItemLabelPosition(position2);
} else if (orientation == PlotOrientation.VERTICAL) {
ItemLabelPosition position1 = new ItemLabelPosition(
ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER);
renderer.setBasePositiveItemLabelPosition(position1);
ItemLabelPosition position2 = new ItemLabelPosition(
ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER);
renderer.setBaseNegativeItemLabelPosition(position2);
}
if (tooltips) {
renderer.setBaseToolTipGenerator(
new StandardCategoryToolTipGenerator());
}
if (urls) {
renderer.setBaseItemURLGenerator(
new StandardCategoryURLGenerator());
}
CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis,
renderer);
plot.setOrientation(orientation);
JFreeChart chart = new JFreeChart(title, font,
plot, legend);
currentTheme.apply(chart);
return chart;
}
}
This is literally ripping their entire source code, found here, and replacing the default font object with the given font object from the constructor.
For your code, replacing
final JFreeChart chart = ChartFactory.createBarChart(
"Latecny histogram", // chart title
"Type", // domain axis label
"Value", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips
false // urls
);
with:
Font customFont = new Font("SansSerif", Font.BOLD, 25);
final JFreeChart chart = CustomChartFactory.createBarChart(
"Latecny histogram", // chart title
"Type", // domain axis label
"Value", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips
false, // urls
customFont //font
);
Should do the trick, assuming you have specified (customFont).
For reference, the default font is
Static Final Font DEFAULT_TITLE_FONT = new Font("SansSerif", Font.BOLD, 18);
This way, the entire chart uses the same font by essentially replacing the default font. SAHIL.R2050's answer is also valid, though it does require that each individual section of the chart have their fonts set.
My answer is good for setting a new default font for all custom charts to use, whereas SAHIIL.R2050's answer is more in line with proper usage of the package.
SAHIL.R2050's answer also allows you to specify the sizes of each section rather than all of them at once.
To sum up the ChartFactory / CustomChartFactory, all it really does is create a ChartTheme then apply it to the chart using it's apply() method.
Hope this helped. :)