在PHP上显示JFreechart画的统计图方法
2018-10-12 13:58
239 查看
如何在PHP上显示JFreechart?可能大部分都遇到这种情况,在JSP上的servlet能完全的显示出JFreechart画的统计图,但是和其他语言混合运用就不能显示了
我现在也遇到这个问题,想了半个小时终于弄明白了,实现的过程还是很简单的。(个人经验总结而已)
解决的思路:
1.先将JFreechart生成的图片保存在web 服务器上。
2.然后在JSP上用<img>标签显示
3.通过JS将JSP导入PHP页面
这样就实现了。
部分getColumnChart.jsp源码:
实现导入JSP的JS源码
我现在也遇到这个问题,想了半个小时终于弄明白了,实现的过程还是很简单的。(个人经验总结而已)
解决的思路:
1.先将JFreechart生成的图片保存在web 服务器上。
2.然后在JSP上用<img>标签显示
3.通过JS将JSP导入PHP页面
这样就实现了。
部分getColumnChart.jsp源码:
<%
String startTime = request.getParameter("startTime");
String endTime = request.getParameter("endTime");
String filter = request.getParameter("filter");
Charts charts = new Charts();
String start = startTime == null ? "2013-05-12" : startTime;
String end = endTime == null ? "2013-11-01" : endTime;
String filters = filter == null ? "eventtype" : filter;
JFreeChart chart = charts
.getPieChart(startTime, endTime, filter);//开始时间、结束时间、filter
String filename = ServletUtilities.saveChartAsJPEG(chart, 800, 400,
null, session);
FileOutputStream fos_jpg = null;
File file = new File(application.getRealPath("")+"/charts");
String path =request.getContextPath()+"/charts/NoData.jpg";
try {
file.mkdirs();
fos_jpg = new FileOutputStream(file.getPath()+"/"+filename);
ChartUtilities.writeChartAsJPEG(fos_jpg, 1.0f, chart, 800, 400,
null);
} catch (Exception e) {
} finally {
try {
fos_jpg.close();
} catch (Exception e) {
}
}
path = request.getContextPath()+"/charts/"+filename;
%>
<div align="center">
<img src="<%=path %>" name="图片" width=800 height=400 border=0>
</div>
实现导入JSP的JS源码
extjs.chart.chart3D = function(nodeid,id){
var panel = new Ext.Panel({
border:false,
fitToFrame: true,//很简单的就一个Html标签
html: '<iframe id="frameHelp" src="/getColumnChart.jsp" frameborder="0" width="100%" height="520" ></iframe>'
});
return panel;
}
您可能感兴趣的文章:
相关文章推荐
- 在PHP上显示JFreechart画的统计图方法
- PHP基于cookie与session统计网站访问量并输出显示的方法
- PHP基于cookie与session统计网站访问量并输出显示的方法
- PHP统计二维数组元素个数的方法
- php根据日期显示所在星座的方法
- PHP将页面中点击数量高的链接进行高亮显示的方法
- PHP生成验证码时“图像因其本身有错无法显示”的解决方法
- php 中文字符入库或显示乱码问题的解决方法
- JFreechart 制作柱状图、饼图、折线图、仪表图等统计图的使用方法
- 让PHP显示Facebook的粉丝数量方法
- PHP二级分类查询显示方法
- PHP实现显示照片exif信息的方法
- nginx+php显示 502 bad gateway的解决方法
- php自定义函数实现统计中文字符串长度的方法小结
- php实现统计网站在线人数的方法
- php获取QQ头像并显示的方法
- nginx+php-fpm配置后页面显示空白的解决方法
- php读取csv文件后,uft8 bom导致在页面上显示出现问题的解决方法
- PHP采用超长(超大)数字运算防止数字以科学计数法显示的方法
- PHP使用redis实现统计缓存mysql压力的方法