Hello,
Does anyone have a simple example of using struts and jfreechart? I'm doing fine producing charts, but am lost as to how to display them in the struts enviroment.
Thanks
RandyT
Struts Example
public ActionForward createPieChart
(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)
throws Exception
{
String pieChartFileName = null;
ReportFBean fBn = (ReportFBean) form;
request.setAttribute("ReportAttribs",fBn);
HttpSession session = request.getSession();
// set the content type so the browser can see this as a picture
response.setContentType("image/png");
//************* Pie Chart implementation***************
//Get dataset
DBPieDataset dbpie = Your DB Handler.getData();
JFreeChart piechart = new .JFreeChart ("name of chart Distribution",dbpie,true,true,true);
//System.out.println("Action class Pie Chart formating done");
ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
pieChartFileName = ServletUtilities.saveChartAsPNG(piechart, 500, 300, info, session);
session.setAttribute("ChartFile", pieChartFileName);
String forward = "pieChart";
return mapping.findForward(forward);
}
Catch this file in jsp and show on brawser.
Hope this helps.
(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)
throws Exception
{
String pieChartFileName = null;
ReportFBean fBn = (ReportFBean) form;
request.setAttribute("ReportAttribs",fBn);
HttpSession session = request.getSession();
// set the content type so the browser can see this as a picture
response.setContentType("image/png");
//************* Pie Chart implementation***************
//Get dataset
DBPieDataset dbpie = Your DB Handler.getData();
JFreeChart piechart = new .JFreeChart ("name of chart Distribution",dbpie,true,true,true);
//System.out.println("Action class Pie Chart formating done");
ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
pieChartFileName = ServletUtilities.saveChartAsPNG(piechart, 500, 300, info, session);
session.setAttribute("ChartFile", pieChartFileName);
String forward = "pieChart";
return mapping.findForward(forward);
}
Catch this file in jsp and show on brawser.
Hope this helps.
struts & jfreechart
hi,
i use a "chartbuilder" and a databean which contains my data, the chartbuilder is static and creates me the plots. i the chartbuilder i create a chart and then i will write it out
filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, info, session);
// write the image to a printwriter
ChartUtilities.writeImageMap(pw, filename, info);
pw.flush();
in the jsp i use it that way..
<%
String filename = ChartBuilder.generateChart( bean,
ChartBuilder.ALL_INTERACTIONS_DATA,
"Name of the Plot ","Time","blabla",
session,
new PrintWriter( out ));
String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;
%>
so if you need some more help, write me..
cheers,
michael
i use a "chartbuilder" and a databean which contains my data, the chartbuilder is static and creates me the plots. i the chartbuilder i create a chart and then i will write it out
filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, info, session);
// write the image to a printwriter
ChartUtilities.writeImageMap(pw, filename, info);
pw.flush();
in the jsp i use it that way..
<%
String filename = ChartBuilder.generateChart( bean,
ChartBuilder.ALL_INTERACTIONS_DATA,
"Name of the Plot ","Time","blabla",
session,
new PrintWriter( out ));
String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;
%>
so if you need some more help, write me..
cheers,
michael
Error of adding jfreechart library to Netbeans Struts
Hi all,
May i know how to add JFreeChart library to Netbeans 5.5 Struts (running on bundled Tomcat) environment as every time i add them, i will get a "Servlet action is not available" error due to actionmapping cannot be found including invoking those actions without using JFreeChart library? However, after i remove it or run it in another generic JSP/Servlet environment(Bundled Tomcat also), everything resumes to normal. For your info, my JFreeChart version is 1.0.5.
Other than that, i also added JasperReport library in the same project using guideline from www.netbeans.org/kb/55/vwp-reports.html. Could it due to the ant script from that site? Kindly help if it is the real root cause as i am totally new to ant script. Thanks in advance!
May i know how to add JFreeChart library to Netbeans 5.5 Struts (running on bundled Tomcat) environment as every time i add them, i will get a "Servlet action is not available" error due to actionmapping cannot be found including invoking those actions without using JFreeChart library? However, after i remove it or run it in another generic JSP/Servlet environment(Bundled Tomcat also), everything resumes to normal. For your info, my JFreeChart version is 1.0.5.
Other than that, i also added JasperReport library in the same project using guideline from www.netbeans.org/kb/55/vwp-reports.html. Could it due to the ant script from that site? Kindly help if it is the real root cause as i am totally new to ant script. Thanks in advance!
Error of adding jfreechart library to Netbeans Struts
Hi all,
May i know how to add JFreeChart library to Netbeans 5.5 Struts (running on bundled Tomcat) environment as every time i add them, i will get a "Servlet action is not available" error due to actionmapping cannot be found including invoking those actions without using JFreeChart library? However, after i remove it or run it in another generic JSP/Servlet environment(Bundled Tomcat also), everything resumes to normal. For your info, my JFreeChart version is 1.0.5.
Other than that, i also added JasperReport library in the same project using guideline from www.netbeans.org/kb/55/vwp-reports.html. Could it due to the ant script from that site? Kindly help if it is the real root cause as i am totally new to ant script. Thanks in advance!
May i know how to add JFreeChart library to Netbeans 5.5 Struts (running on bundled Tomcat) environment as every time i add them, i will get a "Servlet action is not available" error due to actionmapping cannot be found including invoking those actions without using JFreeChart library? However, after i remove it or run it in another generic JSP/Servlet environment(Bundled Tomcat also), everything resumes to normal. For your info, my JFreeChart version is 1.0.5.
Other than that, i also added JasperReport library in the same project using guideline from www.netbeans.org/kb/55/vwp-reports.html. Could it due to the ant script from that site? Kindly help if it is the real root cause as i am totally new to ant script. Thanks in advance!
-
- Posts: 1
- Joined: Thu Aug 09, 2012 10:02 pm
- antibot: No, of course not.
Re: Struts Example
Hi All,
Kindly let me know how do we integrate Struts 1.2 with JFreeChart, in MyEclipse 8.5 ?
Please, if possible, provide the steps because have i searched under the forum and net, did not got relevant answers.
Waiting for favorable response.
Thanks,
Kunal
Kindly let me know how do we integrate Struts 1.2 with JFreeChart, in MyEclipse 8.5 ?
Please, if possible, provide the steps because have i searched under the forum and net, did not got relevant answers.
Waiting for favorable response.
Thanks,
Kunal