在PHP上显示JFreechart画的统计图方法

yipeiwu_com6年前PHP代码库
如何在PHP上显示JFreechart?可能大部分都遇到这种情况,在JSP上的servlet能完全的显示出JFreechart画的统计图,但是和其他语言混合运用就不能显示了

我现在也遇到这个问题,想了半个小时终于弄明白了,实现的过程还是很简单的。(个人经验总结而已)

解决的思路:

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实现针对日期,月数,天数,周数,小时,分,秒等的加减运算示例【基于strtotime】

本文实例讲述了PHP实现针对日期,月数,天数,周数,小时,分,秒等的加减运算方法。分享给大家供大家参考,具体如下: 其实就是strtotime这个内置函数 //PHP 日期 加减 周...

基于PHP magic_quotes_gpc的使用方法详解

PHP magic_quotes_gpc主要是作用在WEB客户服务端的,它的作用时间是从请求开始,接下来我们将具体的为大家讲解它的使用方式。AD:我们今天要向大家介绍的是PHP magi...

PHP获取当前所在目录位置的方法

PHP获取当前所在目录位置的方法

本文实例讲述了PHP获取当前所在目录位置的方法。分享给大家供大家参考。具体分析如下: 如果要获取脚本文件的目录,要应用函数getcwd()来实现。函数声明如下: string getcw...

php实现用手机关闭计算机(电脑)的方法

本文实例讲述了php实现用手机关闭计算机(电脑)的方法。分享给大家供大家参考。具体分析如下: 适合有手机和电脑,用wifi的php web开发。方便关闭你的电脑(尤其在你想睡觉时 ),适...

php实现斐波那契数列的简单写法

斐波那契数列是非常常见的一类数列,其数学定义为:F0=1,F1=1,Fn=F(n-1)+F(n-2)(n>=2,n∈N*)。本文就用php来简单实现斐波那契数列,代码十分简洁易懂,...