Home > Backend Development > PHP Tutorial > How to display statistical charts drawn by JFreechart on PHP_PHP Tutorial

How to display statistical charts drawn by JFreechart on PHP_PHP Tutorial

WBOY
Release: 2016-07-13 10:25:33
Original
831 people have browsed it

How to display JFreechart on PHP? Most people may encounter this situation. The servlet on JSP can completely display the statistical chart drawn by JFreechart, but it cannot be displayed when mixed with other languages ​​​​

Me I also encountered this problem now. After thinking about it for half an hour, I finally figured it out. The implementation process is still very simple. (Just a summary of personal experience)

Solution ideas:

1. First save the images generated by JFreechart on the web server.

2. Then use the tag to display on the JSP

3. Import the JSP into the PHP page through JS

This is achieved.

Part of the getColumnChart.jsp source code:

Copy code The code is as follows:

<%
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);//Start time, end time, 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;
%>



JS source code to import JSP
Copy code The code is as follows:

extjs.chart.chart3D = function(nodeid,id){
var panel = new Ext.Panel({
border:false,
fitToFrame: true ,//It’s very simple, just an Html tag
html: ''
});
return panel;
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825020.htmlTechArticleHow to display JFreechart on PHP? Most of them may encounter this situation. The servlet on JSP can completely The statistical chart drawn by JFreechart can be displayed, but it cannot be displayed when mixed with other languages...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template