如何在PHP上显示JFreechart?可能大部分都遇到这种情况,在JSP上的servlet能完全的显示出JFreechart画的统计图,但是和其他语言混合运用就不能显示了
我现在也遇到这个问题,想了半个小时终于弄明白了,实现的过程还是很简单的。(个人经验总结而已)
解决的思路:
1.先将JFreechart生成的图片保存在web 服务器上。
2.然后在JSP上用标签显示
3.通过JS将JSP导入PHP页面
这样就实现了。
部分getColumnChart.jsp源码:
<BR><% <BR>String startTime = request.getParameter("startTime"); <BR>String endTime = request.getParameter("endTime"); <BR>String filter = request.getParameter("filter"); <BR>Charts charts = new Charts(); <BR>String start = startTime == null ? "2013-05-12" : startTime; <BR>String end = endTime == null ? "2013-11-01" : endTime; <BR>String filters = filter == null ? "eventtype" : filter; <BR>JFreeChart chart = charts <BR>.getPieChart(startTime, endTime, filter);//开始时间、结束时间、filter <BR>String filename = ServletUtilities.saveChartAsJPEG(chart, 800, 400, <BR>null, session); <BR>FileOutputStream fos_jpg = null; <BR>File file = new File(application.getRealPath("")+"/charts"); <BR>String path =request.getContextPath()+"/charts/NoData.jpg"; <BR>try { <BR>file.mkdirs(); <BR>fos_jpg = new FileOutputStream(file.getPath()+"/"+filename); <BR>ChartUtilities.writeChartAsJPEG(fos_jpg, 1.0<strong style="color:transparent">来2源gaodaima#com搞(代@码&网</strong><label>搞gaodaima代码</label>f, chart, 800, 400, <BR>null); <BR>} catch (Exception e) { <BR>} finally { <BR>try { <BR>fos_jpg.close(); <BR>} catch (Exception e) { <BR>} <BR>} <BR>path = request.getContextPath()+"/charts/"+filename; <BR>%> <BR><div align="center"> <BR>" name="图片" width=800 height=400 border=0> <BR>