在PHP上显示JFreechart画的统计图方法
更新时间:2013年11月03日 16:41:19 作者:
在JSP上的servlet能完全的显示出JFreechart画的统计图,但是和其他语言混合运用就不能显示了,下面为大家介绍下如何在PHP上显示JFreechart
如何在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;
}
我现在也遇到这个问题,想了半个小时终于弄明白了,实现的过程还是很简单的。(个人经验总结而已)
解决的思路:
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 杂谈《重构-改善既有代码的设计》之二 对象之间搬移特性
承接上文PHP 杂谈《重构-改善既有代码的设计》之 重新组织你的函数 ,继续说重构方面的内容2012-04-04php 实现账号不能同时登陆的方法分析【当其它地方登陆时,当前账号失效】
这篇文章主要介绍了php 实现账号不能同时登陆的方法,结合实例形式分析了PHP基于session实现当其它地方登陆时,当前账号失效的相关操作技巧,需要的朋友可以参考下2020-03-03ThinkPHP使用PHPExcel实现Excel数据导入导出完整实例
这篇文章主要介绍了ThinkPHP使用PHPExcel实现Excel数据导入导出,非常实用的功能,需要的朋友可以参考下2014-07-07PHP如何使用array_unshift()在数组开头插入元素
这篇文章主要介绍了PHP如何使用array_unshift()在数组开头插入元素,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下2020-09-09
最新评论