最近项目中用到jfreechart,使用的版本是:jfreechart-0.9.8。 如果不进行相关的font的设置,生成的统计图表显示的中文非常模糊。 做了一个例子,可以成功的解决这个问题,拿来与大家共享。
核心代码如下:
JFreeChart chart = ChartFactory.createVerticalBarChart3D(title, domain, range, dataset,true,true,false);
chart.setBackgroundPaint(new GradientPaint(0.0F, 0.0F, Color.white, 1000F, 0.0F, Color.red)); chart.setTitle(new TextTitle(title, new Font("隶书", Font.ITALIC, 15)));
Font font=new Font("黑体",Font.TRUETYPE_FONT, 12);
StandardLegend legend = (StandardLegend) chart.getLegend(); legend.setItemFont(font);
CategoryPlot plot = (CategoryPlot)chart.getPlot(); plot.setForegroundAlpha(0.9F);
CategoryAxis domain_axis = plot.getDomainAxis(); domain_axis.setTickLabelFont(font);
ValueAxis value_axis=plot.getRangeAxis(); value_axis.setTickLabelFont(font);
|
|