Integration of Struts-jfreechart

Source: Internet
Author: User

1: Import Rack Package Jfreechart-1.0.9.jar

2: Write action

 Packageactions;Importjava.util.List;Importorg.jfree.chart.ChartFactory;ImportOrg.jfree.chart.JFreeChart;Importorg.jfree.chart.plot.PlotOrientation;ImportOrg.jfree.data.category.DefaultCategoryDataset;ImportBean. Vote;ImportBean. voteoption;ImportCom.opensymphony.xwork2.ActionSupport;ImportDAO. Votedao;ImportDAO. Voteoptiondao;Importdaofactory.votedaofactory;Importdaofactory.voteoptiondaofactory; Public classVoteresultactionextendsActionsupport {PrivateJfreechart Chart; Private intVoteid;//Poll ID         Public intGetvoteid () {returnVoteid; }     Public voidSetvoteid (intVoteid) {         This. Voteid =Voteid; }     PublicJfreechart Getchart () {Votedao Votedao= Votedaofactory.getvotedaoinstance ();//Get Votedao InstancesVoteoptiondao Voteoptiondao =voteoptiondaofactory.getvoteoptiondaoinstance ();//Get Voteoption Instances//voting by vote IDVote Vote =Votedao.findvotebyid (Voteid); String Votename= Vote.getvotename ();//get the voting name//get all voting options based on the voting IDList<voteoption> voteoptions =Voteoptiondao.findvoteoptionbyvoteid (Voteid); Defaultcategorydataset DCD=NewDefaultcategorydataset ();//Data Source//Setting up data         for(voteoption voteoption:voteoptions) {Dcd.setvalue (Voteoption.getticketnum (),"", Voteoption.getvoteoptionname ()); }        //using the factory class to create a bar chartJfreechart chart =Chartfactory.createbarchart3d (Votename,"Voting Options",                "Number of votes", DCD, plotorientation.vertical,false,                 true,                false); returnChart; }     Public voidSetchart (Jfreechart chart) { This. Chart =Chart; }         PublicString Execute ()throwsException {returnSUCCESS; }}

Configuration information:

<Actionname= "Voteresult"class= "actions. Voteresultaction ">             <resultname= "Success"type= "Chart">                 <paramname= "width">400</param>                 <paramname= "height">300</param>             </result>         </Action>

Integration of Struts-jfreechart

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.