加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-12 19:56:47 所属栏目:PHP教程 来源:网络整理
导读:如何在PHP上显示JFreechart?可能大部分都遇到这种情况,在JSP上的servlet能完全的显示出JFreechart画的统计图,但是和其他语言混合运用就不能显示了 我现在也遇到这个问题,想了半个小时终于弄明白了,实现的过程还是很简单的。(个人经验总结而已) 解决的

如何在PHP上显示JFreechart?可能大部分都遇到这种情况,在JSP上的servlet能完全的显示出JFreechart画的统计图,但是和其他语言混合运用就不能显示了 我现在也遇到这个问题,想了半个小时终于弄明白了,实现的过程还是很简单的。(个人经验总结而已)

解决的思路:

1.先将JFreechart生成的图片保存在web 服务器上。 2.然后在JSP上用标签显示 3.通过JS将JSP导入PHP页面 这样就实现了。

部分getColumnChart.jsp源码:


<div class="codetitle"><a style="CURSOR: pointer" data="3652" class="copybut" id="copybut3652" onclick="doCopy('code3652')"> 代码如下:<div class="codebody" id="code3652">
<%
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,
null);
} catch (Exception e) {
} finally {
try {
fos_jpg.close();
} catch (Exception e) {
}
}
path = request.getContextPath()+"/charts/"+filename;
%>
<div align="center">



实现导入JSP的JS源码


<div class="codetitle"><a style="CURSOR: pointer" data="95366" class="copybut" id="copybut95366" onclick="doCopy('code95366')"> 代码如下:<div class="codebody" id="code95366">
extjs.chart.chart3D = function(nodeid,id){
var panel = new Ext.Panel({
border:false,
fitToFrame: true,//很简单的就一个Html标签
html: ''
});
return panel;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读