JFreeChart 日本語表示
環境によっては、日本語表示が化けることがある。
その際は下記コードを追記することで対応が可能なケースもある。
ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
// sample in struts2 public String t17McapBar() throws IOException{ StockDao dao = StockDao.getInstance(); Date d = dao.getMaxDate(Calendar.getInstance().getTime()); List<SummaryBean> mcapList = dao.getSelectMcapByTse17(d); CategoryDataset dataset = createDatasetSummary(mcapList); // for japanese label ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jfree = ChartFactory.createBarChart("Topix17 mcap", "TopixName", "mcap", dataset, PlotOrientation.HORIZONTAL, false, false, false); ByteArrayOutputStream byteout = new ByteArrayOutputStream(); ChartUtilities.writeChartAsJPEG(byteout, jfree, 1000, 400); setInputStream(byteout.toByteArray()); return "stream"; }
元々の font の指定は awt.font なので、そもそも font.properties の設定がされている必要がある。また、日本語フォントがインストールされている必要もある。
乱暴な検索
find / -name "fontconfig.properties*" 2>/dev/null