Display the statistical chart method drawn by JFreechart on PHP. How to display JFreechart in PHP? Most of them may encounter this situation. the servlet on JSP can completely display the statistical graph drawn by JFreechart, but how to display JFreechart in PHP cannot be displayed if it is used together with other languages? Most of them may encounter this situation. the servlet on JSP can completely display the statistical chart drawn by JFreechart, but it cannot be displayed when used in combination with other languages.
Now I have encountered this problem. after half an hour, I finally figured out that the implementation process is still very simple. (Summary of personal experience)
Solution:
1. save the image generated by JFreechart on the web server.
2. then display it with tags on JSP
3. import JSP to the PHP page through JS
This is achieved.
Some getColumnChart. jsp source 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 (Charts, 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, charts, 800,400,
Null );
} Catch (Exception e ){
} Finally {
Try {
Fos_jpg.close ();
} Catch (Exception e ){
}
}
Path = request. getContextPath () + "/charts/" + filename;
%>
"Name =" image "width = 800 height = 400 border = 0>
JS source code for JSP import
The code is as follows:
Extjs. chart. chart3D = function (nodeid, id ){
Var panel = new Ext. Panel ({
Border: false,
FitToFrame: true, // A simple Html tag
Html :''
});
Return panel;
}
Why? Most of them may encounter this situation. the servlet on JSP can completely display the statistical graph drawn by JFreechart, but it cannot be used together with other languages...