生成图片的方法:
public String generatePieChart(String title,HttpSession session,PrintWriter pw){
String fileName=null;
PiePlot plot=new PiePlot(dedefaltPic());
plot.setInsets(new RectangleInsets(0, 5, 5, 5));
//在统计图片上建立连接。
plot.setURLGenerator(new StandardPieURLGenerator("http://localhost", "section"));
plot.setToolTipGenerator(new StandardPieToolTipGenerator());
JFreeChart chart=new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
TextTitle titles= chart.getTitle();
titles.setFont(new Font("黑体",Font.BOLD,14));//设置标题文字
PiePlot piePlot=(PiePlot)chart.getPlot();//获取图表区域对象
piePlot.setLabelFont(new Font("黑体", Font.BOLD, 12)); //饼图旁边的中文
chart.getLegend().setItemFont(new Font("黑体",Font.BOLD, 12));//设置底部中文
ChartRenderingInfo info=new ChartRenderingInfo(new StandardEntityCollection());
try {
fileName=ServletUtilities.saveChartAsPNG(chart, 500, 300,info, session);
// PrintWriter pws =new PrintWriter(fileName);
// ChartUtilities.writeImageMap(pw, fileName, info,false);
// pw.flush();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return fileName;
Action中方法:
public String webChart(){
WebChart chart=new WebChart();
OutputStream out=null;
try {
// out=this.getResponse().getOutputStream();
// PrintWriter pw=new PrintWriter(out);
this.fileName=chart.generatePieChart("水果产量图",ServletActionContext.getRequest().getSession(), null);
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
fileName= ServletActionContext.getRequest().getContextPath()+"servlet/DisplayChart?filename="+fileName;
out=null;
return "toWebChart";
}jsp中调用
<img alt="aaa" src="${fileName}" width="400" height="300">生成的路径是src=" /snpecservlet/DisplayChart?filename=jfreechart-6151396563597141489.png"
解决方案 »
- 关于一个很头痛的问题——乱码
- 文章中关键字的过滤问题
- 将mp4嵌入页面,并用javascript动态改变src的内容
- java主要应用在哪方面
- 参数传递的问题
- 关于next()的使用方法。比如在WHILE中。
- 新建第一个web工程,运行老是出错,
- 很奇怪!!我的bean一点问题也看不出来,可是运行的时候出错!!java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid curs
- 关于war包发布后的url目录问题?
- SCRIPT language=JScript.Encode这一句是什么意思呀!
- mybaits3 mapper.xml文件中查询in的语法
- jsp urlwriter如何配置
就可以看到效果了
顶一下..