Required Packages:
Struts2-jfreechart-plugin-2.2.1.1.jar
Jfreechart-1.0.13.jar
Jcommon-1.0.17.jar
In the foreground JSP page, you can use the IFRAME to display the chart, code
<id= "frm1" name= "Frm1" src= "/lzmgzyx/jfreechart.action" style= "width:100%; height:700px "></iframe>
Configuration in Struts.xml, note the type of inheritance Jfreechart-default,result is chart
<PackageName= "/lzmgzyx"Extends= "Struts-default,jfreechart-default"Namespace= "/lzmgzyx"><ActionName= "Jfreechart"Class= "Com.demo.jfreechart.JfreechartAction"><ResultName= "Success"Type= "Chart"><Paramname= "height" >650 </param> <param name= " Width ">1300</ Param> </result > </action> </package
The action must have a chart global variable, providing a GET, set method
Private Jfreechart chart;
After the foreground submits the request, the method in Aciton generates a chart object back to the foreground.
Example of a method in action
Public String Execute () { new defaultcategorydataset (); Dataset.addvalue (15, "First comparison", "first item"); Dataset.addvalue (25, "First comparison item", "Second item"Truereturn SUCCESS;}
Generated chart
STRUTS2 Integrated Jfreechart