I have a problem to set encoding of JFreeChart chart title font. I created pdf and added chart to it. I created custom font using itext library and set encoding to CP1250. The special characters shows in pdf, I mapped this font to java.awt.Font but the same letters doesnt show on chart title. Is there any other way to achieve this goal?
JFreeChart chart = ChartFactory.createBarChart3D(null,"Rok","Liczba wszystkich emisji", dataset, PlotOrientation.VERTICAL, true, true, true);
BaseFont baseFont = BaseFont.createFont(BaseFont.HELVETICA,BaseFont.CP1250, BaseFont.CACHED);
Font font = new Font(baseFont, 9);
document.add(new Paragraph("śćżźółąę abcdefhgijklmnop", font));
DefaultFontMapper defaultFontMapper = new DefaultFontMapper();
java.awt.Font titleFont = defaultFontMapper.pdfToAwt(baseFont,20);
StandardChartTheme chartTheme = new StandardChartTheme("theme");
chartTheme.setRegularFont(titleFont);
ChartFactory.setChartTheme(chartTheme);
chart.setTitle(new TextTitle("śćżźółąę abcdefhgijklmnop"));
chart.getTitle().setFont(titleFont);
Not sure. But maybe you need to set your font also for the ExtraLarge and Large variants of the theme. Maybe try something like this:
JFreeChart chart = ChartFactory.createBarChart3D(null,"Rok","Liczba wszystkich emisji", dataset, PlotOrientation.VERTICAL, true, true, true);
BaseFont baseFont = BaseFont.createFont(BaseFont.HELVETICA,BaseFont.CP1250, BaseFont.CACHED);
Font font = new Font(baseFont, 9);
document.add(new Paragraph("śćżźółąę abcdefhgijklmnop", font));
DefaultFontMapper defaultFontMapper = new DefaultFontMapper();
java.awt.Font titleFont = defaultFontMapper.pdfToAwt(baseFont,20);
StandardChartTheme chartTheme = new StandardChartTheme("theme");
chartTheme.setExtraLargeFont(font.deriveFont(24f));
chartTheme.setLargeFont(font.deriveFont(16f));
chartTheme.setRegularFont(font.deriveFont(12f));
chartTheme.setSmallFont(font.deriveFont(10f));
ChartFactory.setChartTheme(chartTheme);
ChartFactory.setChartTheme(chartTheme);
chart.setTitle(new TextTitle("śćżźółąę abcdefhgijklmnop"));
chart.getTitle().setFont(titleFont);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.