fonts - 如何在 JFreeChart 图表中使用自定义字体?

标签 fonts jfreechart custom-font

如何在 JFreeChart 图表中使用自定义字体?更多详细信息:我有时间序列图表和字体文件geogtqrg.ttf。所以我需要将此字体分配给图表?

谢谢回复!

看来这个任务可以通过setLabelFont来解决,但是如何在这个方法中正确定义字体文件呢?

最佳答案

使用org.jfree.chart.StandardChartTheme提供了使用字体的一定一致性。只是create您的Font,在ChartTheme中指定所需的字体,并要求ChartFactory在创建新图表时为您应用新主题。做这样的事情(未经测试的)片段:

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);

关于fonts - 如何在 JFreeChart 图表中使用自定义字体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16397341/

相关文章:

html - 彩色变音符号和 unicode 行为

java - 将 JfreeChart 添加到 SVG 图像

c# - 使用自定义字体在标签中绘制文本时参数无效

java - 这个: Exception in thread "AWT-EventQueue-0" java. lang.ExceptionInInitializerError是什么?

Android - 使用自定义字体

ios7 - UITextView 在 iOS 7 中错误地渲染自定义字体

google-chrome - Chrome 无法解码下载的字体 OTS 解析错误 : post: Failed to parse table

java - 一行的 JtextPane

android - 如何以编程方式将 Google Fonts .xml 设置为 TextView

java - JFreechart 右键单击​​ XYItemEntity