日期:2014-05-19  浏览次数:20657 次

struts2整合jfreechart1.0.14 中文显示问题
由于毕业设计想用jfreechart1.0.14做报表统计,但是图片显示出来后中文无法正常显示,都变成了方框,而且我已经对字体进行了设置,求教各位网友....
Action部分代码:
Java code

HttpServletRequest request=ServletActionContext.getRequest();
HttpSession session=request.getSession();
CategoryDataset dataset = DatasetUtilities.createCategoryDataset(rowKeys, columnKeys, data);
JFreeChart chart = ChartFactory.createBarChart3D(title,
        x,
        y,
        dataset,
        PlotOrientation.VERTICAL,
        true,
        true,
        false); 
CategoryPlot plot = chart.getCategoryPlot();

//设置字体,不然会中文乱码
Font font = new Font("宋体", Font.BOLD, 16); 
TextTitle title1 = new TextTitle(title, font);
chart.setTitle(title1); //标题
        
NumberAxis numberaxis = (NumberAxis) plot.getRangeAxis();
CategoryAxis domainAxis = plot.getDomainAxis();  
domainAxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 11));     /*------设置X轴坐标上的文字-------*/ 
domainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 12));       /*------设置X轴的标题文字------------*/  
numberaxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 12)); /*------设置Y轴坐标上的文字-----------*/  
numberaxis.setLabelFont(new Font("黑体", Font.PLAIN, 12));      /*------设置Y轴的标题文字------------*/
chart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 12));
        



jsp也设置了编码:
HTML code

<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>



------解决方案--------------------
文件本身的编码 改成 utf8