jfreechart 出现乱码问题

[复制链接]
查看11 | 回复3 | 2010-5-21 11:53:01 | 显示全部楼层 |阅读模式
代码如下:
DefaultPieDataset piedata = new DefaultPieDataset();
//第一个参数为名称,第二个参数是double数
piedata.setValue("空座", tj1);
piedata.setValue("预定", tj3);
piedata.setValue("已售", tj2);
//创建JFreeChart,都使用ChartFactory来创建JFreeChart,很标准的工厂设计模式
JFreeChart chart = ChartFactory.createPieChart(title, piedata, true, true, true);
chart.setBackgroundPaint(Color.white);
String filename = ServletUtilities.saveChartAsPNG(chart, 650, 350, null, session);
FileOutputStream fos_jpg = null;
String graphURL = new java.io.File(request.getRealPath(request.getServletPath())).getParent() + "/upload/" + filename;
try {


fos_jpg=new FileOutputStream(graphURL);


ChartUtilities.writeChartAsJPEG(fos_jpg,1.0f,chart,640,480,null);


fos_jpg.close();

} catch (Exception e) {
e.printStackTrace();
}

回复

使用道具 举报

千问 | 2010-5-21 11:53:01 | 显示全部楼层
最主要的是设置fontjfreechart中文乱码问题解决方案(转)柱状图(CategoryPlot):
CategoryPlot plot=chart.getCategoryPlot();//获取图表区域对象 CategoryAxis domainAxis=plot.getDomainAxis();
//水平底部列表
domainAxis.setLabelFont(new Font("黑体",Font.BOLD,14));
//水平底部标题
domainAxis.setTickLabelFont(new Font("宋体",Font.BOLD,12));
//垂直标题
回复

使用道具 举报

千问 | 2010-5-21 11:53:01 | 显示全部楼层
生成图像之前 加上下列代码:
response.setHeader("Pragma", "No-cache");response.setHeader("Cache-Control", "no-cache");response.setDateHeader("Expires", 0);response.se
回复

使用道具 举报

千问 | 2010-5-21 11:53:01 | 显示全部楼层
sqtds 正解。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行