Question

How can I use custom fonts in JFreeChart diagrams? More details: I have the Time Series Chart and font file geogtqrg.ttf. So I need to assign this font to chart?

Thanks for reply!

It seems to be, that this task can be solved by setLabelFont, however how to define the font-file in this method correctly?

Was it helpful?

Solution

Using org.jfree.chart.StandardChartTheme offers some consistency in using font's. Just create your Font, specify the desired font(s) in a ChartTheme, and ask ChartFactory to apply the new theme for you when creating new charts. Do something like this (untested) fragment:

Font font = Font.createFont(Font.TRUETYPE_FONT, new File("geogtqrg.ttf"));
StandardChartTheme chartTheme = new StandardChartTheme("GeoTheme");
chartTheme.setExtraLargeFont(font.deriveFont(24f));
chartTheme.setLargeFont(font.deriveFont(16f));
chartTheme.setRegularFont(font.deriveFont(12f));
chartTheme.setSmallFont(font.deriveFont(10f));
ChartFactory.setChartTheme(chartTheme);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top