=====================解决方法1======================
JFreeChart 设置图例字体
悬赏分:20 - 提问时间2008-12-10 11:15 问题为何被关闭
操作系统是日文XP,数据库内容是中文的,结果在JSP页面显示的时候图例的字体变成了一个个的小方块,我知道要设置字体,但是不知道具体怎么设置,谁能告诉我?
我这里做的是柱图,X轴和Y轴的内容一开始也是乱码,后来找到设置字体的的方法:
//获取横坐标
CategoryAxis domainAxis = plot.getDomainAxis();
//获取纵坐标
NumberAxis numberaxis = (NumberAxis) plot.getRangeAxis();
//将纵坐标间距设置为100
numberaxis.setTickUnit(new NumberTickUnit(100));
numberaxis.setLabelFont(new Font("SimSun",Font.PLAIN,13));
numberaxis.setTickLabelFont(new Font("SimSun",Font.PLAIN,12));
//设置横坐标的标题字体和大小
domainAxis.setLabelFont(new Font("SimSun",Font.PLAIN,13));
//设置横坐标的坐标值的字体
domainAxis.setTickLabelFont(new Font("SimSun",Font.PLAIN,12));
//使横坐标设置生效
plot.setDomainAxis(domainAxis);
ValueAxis rangeAxis = plot.getRangeAxis();
图例的字体怎么设置???
问题补充:半天了都没人来回答,打算把分送给1楼~
唉~花了一点时间,已经搞定了,贴下代码:
---------我是分割线-----------------
// 取得统计图表的第一个图例
LegendTitle legend = chart.getLegend(0);
//设置图例的字体
legend.setItemFont(new Font("SimSun",Font.BOLD,13));
------------我还是分割线----
=====================解决方法2======================
调用ChartFactory.setChartTheme(),改变Chart的主题就可以了::
StandardChartTheme standardChartTheme = new StandardChartTheme("suzog");//这里的"name"参数;可以任意替换
standardChartTheme.setLargeFont(new Font("楷体",Font.BOLD, 12));//可以改变轴向的字体
standardChartTheme.setRegularFont(new Font("宋体",Font.BOLD, 12));//可以改变图例的字体
standardChartTheme.setExtraLargeFont(new Font("隶书",Font.BOLD, 12));//可以改变图标的标题字体
ChartFactory.setChartTheme(standardChartTheme);//设置主题
参考资料:JFreeChart-API+自己