Recently do imagine to be on the web side to display the chart, there are many graphics plug-in,Jfreechart is also good, but I chose chartdirector.
First, demand: Pagination shows the student access to the number of the bar chart, (I have crawled some courses on the site, and recorded the user Access Records)
Second, realize:
(1) Chartdirector bring a JSP file, copy it into the project, and bring the Chartdirector.jar package into the project
(2) To display the JSP interface of the chart, where Chart1url and ImageMap1 are handled by the action layer to pass over the data, pagination code can be ignored, in fact, the actual interface code is a few lines.
<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
(3) Action layer, some comments have been marked on, garbled problem set default text C.setdefaultfonts ("SIMSUN.TTC"), paged Query method is not much said, will get Chart1url and ImageMap1 string back to the JSP interface
/** browsing record */public String Visitrecord () throws Exception{int i,recordcount=0;//remove student student Stufind=getcurrentuser (). Getstudent ();//Take out the course of the access string hql= "from Visitcourserecord WHERE student=?"; List<object> parameters=new arraylist<object> ();p arameters.add (stufind); int s=parameters.size (); Pagebean Pagebean=visitcourserecordservice.getpagebean (Pagenum, hql, parameters); List<visitcourserecord> courselist=pagebean.getrecordlist (); Actioncontext.getcontext (). Getvaluestack (). push (Pagebean);//Record strip recordcount=courselist.size ();// Data--Shows the number of access records double[] count=new double[courselist.size ()];for (i=0;i<recordcount;i++) {count[i]=courselist.get (i) . GetCount ();} Data--title to display string[] labels = new String[courselist.size ()];for (i=0;i<recordcount;i++) {Labels[i]=courselist.get (i). Getspidercourse (). GetName ();} Create 1000*800 Chartxychart c = new XYChart (+), c.setdefaultfonts ("SIMSUN.TTC");//Add graphics title----18pt Arial C.addtitle ( "Access to Course Records", "Arial", ();//Set the PlotArea at (max) and of sizeX 280 pixels. Use a vertical gradient color from//light blue (Eeeeff) to Deep Blue (0000cc) as background. Set border and grid lines to white//(FFFFFF). C.setplotarea (+, +, +, C.lineargradientcolor, 0xe Eeeff, 0x0000cc),-1, 0XFFFFFF, 0XFFFFFF);//Add a multi-color bar chart layer using the supplied data. Use soft lighting effect with light//direction from Left.c.addbarlayer3 (count). setBorderColor (Chart.transparent, Chart.softlighting (Chart.left));//Set Text C.xaxis (). Setlabels (labels);//Set text and direction 65 degrees C.xaxis (). Setlabelstyle ("Arial", 10 ). Setfontangle;//Draw The ticks between label positions (instead of at label positions) C.xaxis (). Settickoffset (0.5); Add a title to the Y axis with 10pt Arial bold Fontc.yaxis (). Settitle ("Number of visits", "Arial", ();//Set Axis line width to 2 pixel Sc.xaxis (). SetWidth (2); C.yaxis (). SetWidth (2);//Output the chartstring Chart1url = C.makesession ( Servletactioncontext.getrequest (), "Chart1");//Include tool tip for the chartstring imageMap1 = C.gethtmlimagemap ("", "", "Title= ' {Xlabel}: US $ {value}m '"); Actioncontext.getcontext (). Put ("Chart1url", Chart1url); Actioncontext.getcontext (). Put ("ImageMap1", ImageMap1); return "Visitrecord";}
(4) The other is the SSH framework of things, not to mention hereThird, test:
Paging Information:
Below the yellow logo is chartdirector itself belt, online has cracked method, version of the reason, here is no longer given.
Iv. Summary
At the beginning of the Chartdirector to the JSP display diagram of the demo is written in the JSP interface Java code, some preparation data code, you can move to the action or other processing code, only need to provide IMG src URL and map value. There are Chinese garbled problems, but also in the online search for some solutions, about which settings are also used to constantly familiar.
Java EE SSH framework uses chartdirector drawing