Struts Example

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
randyt

Struts Example

Post by randyt » Fri Oct 01, 2004 4:42 pm

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

anjali
Posts: 7
Joined: Thu Sep 11, 2003 9:51 am
Location: India

Post by anjali » Fri Oct 29, 2004 8:32 am

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.

mkleen
Posts: 6
Joined: Mon Oct 18, 2004 4:13 pm

struts & jfreechart

Post by mkleen » Fri Oct 29, 2004 3:40 pm

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

bieira
Posts: 2
Joined: Tue May 08, 2007 5:33 pm

help

Post by bieira » Wed May 09, 2007 9:22 am

Hello,
Does anyone have a simple example of using struts and jfreechart?

i just tried and i can't put it work....

:cry:

bieira

Kyaw
Posts: 13
Joined: Wed May 23, 2007 10:34 am
Location: Singapore

Error of adding jfreechart library to Netbeans Struts

Post by Kyaw » Wed May 23, 2007 11:01 am

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!

Kyaw
Posts: 13
Joined: Wed May 23, 2007 10:34 am
Location: Singapore

Error of adding jfreechart library to Netbeans Struts

Post by Kyaw » Wed May 23, 2007 11:04 am

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!

kkunal2005
Posts: 1
Joined: Thu Aug 09, 2012 10:02 pm
antibot: No, of course not.

Re: Struts Example

Post by kkunal2005 » Thu Aug 09, 2012 10:23 pm

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

Locked